質問

私は色付きのAndroidボタンの描画を設計し、それらをタブレルアウトに入れます。問題は、Androidのデフォルトのボタンがセルスペース全体を占有しないということですが、DOWARDABLESはDO(貼り付けの貼り付けを参照)。Drowablesがデフォルトのボタンのように少しスペースを離れないように、XMLを調整するにはどうすればよいですか。私は下部にXMLコードを貼り付けました。

カスタムボタン:

利用可能なセルスペースをすべて取得するカスタムボタン

デフォルトボタン:

デフォルトボタンのgapsを残す

XMLコード:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"><shape>
            <gradient android:angle="90" android:endColor="@color/dark_red" android:startColor="@color/brick_red" />

            <corners android:radius="10dip" />

            <padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip"></padding>

        </shape></item>
    <item android:state_focused="true"><shape>
            <gradient android:angle="270" android:endColor="@color/dark_red" android:startColor="@color/brick_red" />

            <corners android:radius="10dip" />

            <padding android:bottom="10dip" android:left="10dip" android:right="10dip" android:top="10dip" />
        </shape></item>
    <item><shape>
            <gradient android:angle="270" android:endColor="@color/dark_red" android:startColor="@color/red" />

            <corners android:radius="10dip" />

            <padding android:bottom="5dip" android:left="5dip" android:right="5dip" android:top="5dip" />
        </shape></item>

</selector>
.

あなたの助けをありがとう:)

役に立ちましたか?

解決

Did you try to use the Top, Left, Bottom and Right attributes of items ? See : How to add padding to gradient <shape> in Android?

Alternatively, in your final layout that uses the button, you could use the attribute : android:layout_margin(Right,Left,Top,Bottom)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top