androidにおけるshapeの詳細

2042 ワード

通常、「レイアウト」「コントロール」などのviewに背景を設定したり、グラデーションや特殊な効果がある場合は画像と色を採用しますが、画像は引っ張られるリスクに直面する可能性があります(9.pngで処理することもできます)、単純に
色を使うのは現実的で特殊な効果では実現しにくい.だから、あなたのアプリケーションのために今の派手な効果の時間を使いたいときは、shopeはあなたの仁に譲らない選択です.Shapeのすべてのサブプロパティ:gradient--対応するカラーグラデーションをまとめます.startcolor、endcolorはあまり言わない.Android:angleとは、どの角度から変化するかを指します.solid--塗りつぶします.stroke--線を描きます.Corners--フィレット.
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/white" />
    <stroke android:width="1.0dip" android:color="#ffe0e0e0" />
    <corners android:radius="4.0dip" />
</shape>
<?xml version="1.0" encoding="utf-8"?>

<shape 

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

         <gradient 

          android:startColor="#ffffffff"

          android:centerColor="#FE8B1A"

          android:endColor="#ffcccccc"

          angle="270"

          android:centerX="0.5"

          android:centerY="0.5"

          />

         <padding android:left="7dp"

          android:top="7dp"

          android:right="7dp"

          android:bottom="7dp"/>

         <corners android:radius="4dp"/>

</shape>

<!--

  shape            ,      、   ,       , 

  gradient           、           、  、    

                 (0,90,180      ,270      )      

  padding              

  corners            

-->