視覚的な例は、この種の質問に役立ちます。
ボイラープレート
グラデーションを作成するには、res / drawableにxmlファイルを作成します。私は私のmy_gradient_drawable.xmlを呼び出しています:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="0"
android:startColor="#f6ee19"
android:endColor="#115ede" />
</shape>
いくつかのビューの背景に設定します。例えば:
<View
android:layout_width="200dp"
android:layout_height="100dp"
android:background="@drawable/my_gradient_drawable"/>
type = "linear"
設定しangle
用linear
タイプ。45度の倍数でなければなりません。
<gradient
android:type="linear"
android:angle="0"
android:startColor="#f6ee19"
android:endColor="#115ede" />

type = "radial"
設定しgradientRadius
用radial
タイプ。使用%p
するとは、親の最小寸法のパーセンテージを意味します。
<gradient
android:type="radial"
android:gradientRadius="10%p"
android:startColor="#f6ee19"
android:endColor="#115ede" />

type = "sweep"
なぜ誰かがスイープを使用するのかはわかりませんが、完全を期すために含めています。角度を変更する方法がわからなかったので、1つの画像のみを含めています。
<gradient
android:type="sweep"
android:startColor="#f6ee19"
android:endColor="#115ede" />

センター
スイープまたはラジアルタイプの中心を変更することもできます。値は、幅と高さの割合です。%p
表記法も使用できます。
android:centerX="0.2"
android:centerY="0.7"
