轉;http://wang-peng1.iteye.com/blog/523869
在GradientDrawable1試圖中終於把shape學會了,以前總是似懂非懂,現在終於把裡面的東西搞清楚了,同時也挺佩服Google的用心,故意設定一些陷阱吧,不認真對待還真以為沒有啥效果呢。
setContentView(R.layout.shape_drawable_1)
shape_drawable_1 代碼如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:src="@drawable/shape_1" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:src="@drawable/line" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:src="@drawable/shape_2" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/line" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:src="@drawable/shape_3" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="20dip"
android:src="@drawable/line" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:src="@drawable/shape_4" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/line" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:src="@drawable/shape_5" />
</LinearLayout>
</ScrollView>
shape_5的代碼:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
android:angle="270"/>
<padding android:left="50dp" android:top="20dp"
android:right="7dp" android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
gradient 產生色彩坡形 android:angle 從哪個角度開始變 貌似只有90的整數倍可以
android:shape="rectangle" 預設的也是長方形
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#ff4100ff"/>
<stroke android:width="2dp" android:color="#ee31ff5e"
android:dashWidth="3dp" android:dashGap="2dp" />
<padding android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
<corners android:radius="6dp" />
</shape>
#ff4100ff藍色#ff4100ff綠色
<solid android:color="#ff4100ff"/>實心的 填充裡面
<stroke 描邊 採用那樣的方式將外形輪廓線畫出來
android:dashWidth="3dp" android:dashGap="2dp" 預設值為0
android:width="2dp" android:color="#FF00ff00"筆的粗細,
android:dashWidth="5dp" android:dashGap="5dp" 實現- - -這樣的效果,dashWidth指的是一條小橫線的寬度
dashGap 指的是 小橫線與小橫線的間距。 width="2dp" 不能太寬