Android 圖形狀態組合的應用 (筆記 ),android圖形
目的:建立按鈕,當按鈕使按鈕有不同的形狀狀態
在res下drawable-hdpi儲存按鈕初始狀態left.png和按鈕按下後的狀態圖片rigth.png.
將圖片檔案拖到建立好的檔案夾drawable-hdpi中
建立一個一般的XML檔案,建立圖形狀態組合步驟為
drawable_change → New → Other... → XML → XML File
注意:將Left_Rigth.XML 改成 left_right.XML
在Left_Right.XML填入以下代碼
<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 按的狀態 --> <item android:state_pressed="true" android:drawable="@drawable/left"/> <!-- 預設的狀態 --> <item android:drawable="@drawable/rigth"/></selector>
在 activity_main.XML加以下代碼
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.test.MainActivity" tools:ignore="MergeRootFrame" > <Button android:id="@+id/button1" android:layout_width="30dp" android:layout_height="wrap_content" android:background="@drawable/left_right"/> <Button android:id="@+id/button2" android:layout_width="30dp" android:layout_height="wrap_content" android:layout_below="@id/button1" android:background="@drawable/left_right"/> </RelativeLayout>
測試結果如下:
轉載請註明出處:http://blog.csdn.net/u010499449/article/details/42192383