Android: Comment arrêtez-vous les boutons personnalisés de prendre tous les espaces de cellule disponibles dans une mesure?

StackOverflow https://stackoverflow.com/questions/9034595

Question

J'ai conçu des poulatables de boutons Android colorés et mettez-les dans une napperon.Le problème est que les boutons par défaut de Android ne prennent pas l'ensemble de l'espace de cellule, mais mes érables font (voir des images attachées).Comment puis-je régler mon XML de sorte que mes érables laissent un peu d'espace comme les boutons par défaut?J'ai collé le code XML en bas.

boutons personnalisés:

boutons personnalisés prenant tout espace de cellule disponible

Boutons par défaut:

Les boutons par défaut laissent des lacunes

code 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>

Merci pour votre aide :)

Était-ce utile?

La solution

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)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top