[Android] XML을 통한 투명 그래디언트
4845 단어 Android
gradation.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
android:angle="270"
android:startColor="#ffff0000"
android:endColor="#00ffffff"
/>
</shape>
첫 번째 ff는 "#ff0000"이고 00번째 "#00fff"는 투명도입니다.배치에 다음과 같은 방식으로 배치하면 된다.
투명하기 때문에 아래처럼 다른 뷰에 겹칠 수도 있습니다.
그래디언트
상술한 방법을 적용하면 다음과 같은 점차적인 변화를 진행할 수 있다.
gradation.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
android:angle="90"
android:startColor="#ffffffff"
android:centerColor="#aaffffff"
android:endColor="#00ffffff"
/>
</shape>
activity_main.xml<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="io.github.hkusu.sampleapp.MainActivity"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_android_black_18dp"
/>
<View
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/gradation"
/>
</FrameLayout>
</RelativeLayout>
Reference
이 문제에 관하여([Android] XML을 통한 투명 그래디언트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hkusu/items/5430ad16872ed226103b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)