我正在嘗試在xml創建的按鈕上添加點擊效果。到目前爲止,我得到了clickeffect運行,但我無法設置提供點擊效果相同的圓角,我對未點擊的按鈕;這樣看起來很可怕。在我的gradient.xml
中,我提供了與圓角相同的圖像佈局,但似乎忽略了此設置。在帶填充角的自定義按鈕上添加點擊效果
有人能指出我正確的方向嗎?
< --->
我的盒子clickeffect.xml:(box_with_click_effect.xml)
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/rounded_box" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/gradient" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/gradient" />
<item android:drawable="@drawable/rounded_box" />
</selector>
我的按鈕抽拉的XML:(rounded_box.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/my_orange"/>
<corners android:radius="15px"/>
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
</shape>
我gradient.xml的點擊狀態:(gradient.xml)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<!-- THIS DOESN'T WORK: <bitmap android:src="@drawable/rounded_box"/>
SO I TRY THIS: -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/cocus_orange"/>
<corners android:radius="15px"/>
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#880d0d0f"
android:endColor="#885d5d5e"/>
</shape>
</item>
</layer-list>
爲什麼不使用九個補丁繪製背景http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch。這裏有一個博客http://www.dibbus.com/2011/03/9patch-images-in-android/ – Raghunandan
,因爲我是一名新手,我想習慣通過xmls進行造型。 – bofredo