Android学習/drawable


ダイレクトコードを使用してdrawableを描画する


📎 グラデーションイメージの作成

  • <グラデーション>タグ
  • を使用

    ツールバーの

  • 角:ランプ方向の設定に必要な回転角度
  • を指定します.
  • startColor:開始色
  • centerColor:中央色
  • endColor:終了カラー
  • サンプルコード2479182
    <?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="#E2FFC0"
            android:centerColor="#FFF8B7"
            android:endColor="#FFC5C1"
            />
        
    </shape>
  • サンプルコード結果
  • 📎 中心が空の長方形を作成

  • タグ
  • を使用
    サンプルコード2479182
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    
        <stroke
            android:color="#2196f3"
            android:width="30dp"/>
    
    </shape>
  • サンプルコード結果
  • 📎 前の例では中央の長方形を作成しました

  • ラベルを併用
  • 筆画は線を表し、実体は面を表す.
  • サンプルコード2479182
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    
        <solid
            android:color="#2196f3"/>
    
        <stroke
            android:color="@color/white"
            android:width="30dp"/>
    
    </shape>
  • サンプルコード結果
  • 📎 円の長方形を作成

  • <コーナー>タグ
  • を使用
  • 角ごとに異なる程度の円を作ることができます.
  • サンプルコード2479182
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    
        <solid
            android:color="#FF9797"/>
    
        <corners
            android:bottomLeftRadius="20dp"
            android:topLeftRadius="50dp"
            android:bottomRightRadius="30dp"
            android:topRightRadius="200dp"/>
        
    </shape>
  • サンプルコード結果