カスタムdrawable ressourceのButtonからパディングを変更してセレクタで再利用しようとしています。 描画可能に変更しても問題ないようだが、アプリが常に異なるドローアブルからaviable最高のパディングを使用します。Selector DrawableのPaddingを変更する
button_inactive.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#FF4d681f" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFFFF" />
<padding
android:bottom="5dp"
android:top="5dp" />
</shape>
</item>
button_active.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#FF4D681F" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle" >
<solid android:color="#FF8da32d" />
<padding
android:bottom="10dp"
android:top="10dp" />
</shape>
</item>
を
button_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button_active"/>
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/button_active"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/button_active"/>
<item android:drawable="@drawable/button_inactive"/>
問題は、私のボタンが「非アクティブ」状態を含むすべての状態で10dpのパディングを使用していることです。
XMLでのみ動作するようにするにはソリューションがありますか、またはカスタムボタンをプログラム的に作成する方が良いですか?
私はドロウアブルボタンで試してみました。通常のものにはパディングがありません。そして、そのパディングにパディングを追加しました。通常のものを表示していても、押したものからのパディングを使用します。私は同じ方法で使用している.pngファイルにも問題があります。私は、プレスされたものを普通のものより大きくしましたが、サイズは変わりません。これは吸う。 –
http://stackoverflow.com/a/19227057/1645319 –