1
0

More than 1 year has passed since last update.

XMLでViewにグラデーションの設定をする

Posted at

まずはdrawableにグラデーションの設定をしていきます

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="270"
        android:startColor="#ffffff"
        android:endColor="#0000ff" />
</shape>

それぞれ説明していきます

android:angle="270"

アングル、つまりグラデーションをかける角度のことです
その角度を270度に設定することによって 上から下に向けてのグラデーションをかけることができます
グラデーションをかけたい方向を変えたいときは android:angle を調整しましょう
0(未設定)では左から右へ
90 で 下から上へ
180で 右から左へ のグラデーションになります

android:startColor="#ffffff"

ffffff は white

android:endColor="#0000ff"

0000ff は blue

カラーコードや色の名前は
WEB色見本 原色大辞典
より

今回はwhiteからblue になる設定をしました

そして先ほどのdrawableを グラデーションをかけたいbackgraundに設定すると

スクリーンショット 2022-02-20 21.51.40.png

上から下にかけて白から青にグラデーションのかかったbackgroundを設定することできました

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0