Android の背景色の放射状グラデーションは、res/drawable の XML ファイルで定義できます (XML ファイルの名前は個別に定義できます)。
1.radial_gradient.xmlコード:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#95C5F3"
android:centerColor="#C36E6E"
android:endColor="#C3E89B"
android:type="radial"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="200dp"/>
</shape>
1. android:startColor 開始色
2. android:centerColor 中間色
3. android:endColor 終了色
4. android:type グラデーションタイプ、ラジアル
5. centerX、centerY: 中心半径点の x および y 座標、値は 0 ~ 1.0、centerX は水平方向のセンタリングを示すために 0.5 を取り、centerY は垂直方向のセンタリングを示すために 0.5 を取ります。
6. gradientRadius: グラデーションカラーの半径
2. 実装するインターフェースでそれを使用します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".ColorActivity"
android:orientation="vertical"
android:background="@drawable/radial_gradient">
</LinearLayout>