Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

padding image from xml selector

Tags:

android

I'm trying to padd my button background image of my main menu (I'm using a selector for the different states), doing it on this way (buttoninicio_custom.xml):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/botoninicial_pressed"
          android:state_pressed="true">

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

    </item>
    <item android:drawable="@drawable/botoninicial_pressed"
          android:state_focused="true">

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

    </item>
    <item android:drawable="@drawable/botoninicial">
            <padding
            android:left="10dp"
            android:top="10dp"
            android:right="10dp"
            android:bottom="10dp" />
    </item>
</selector>

..but the padding has no effect. What I should do to solve this problem??

I already used "bitmap" tag inside each "item" tag with the padding inside, but it's still doing anything!!!

My main button looks this way:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button2"
        android:layout_width="180dp"
        android:layout_height="50dp"
        android:layout_marginBottom="15dp"
        android:textSize="16sp"
        android:textColor="#FFFFFF"
        android:background="@drawable/buttoninicio_custom"
        android:text="@string/idmMENU2" />
</LinearLayout>

"Because if I set android:padding inside the "button" tag, it pads me the text not the background image... The problem it's that when I pressed the main button: My image background change correctly but the new image appear cut."

like image 470
user1592470 Avatar asked Sep 03 '12 12:09

user1592470


1 Answers

Wrap it in a layer-list:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="3dp"
        android:left="3dp"
        android:right="3dp"
        android:top="1dp">

        <selector xmlns:android="http://schemas.android.com/apk/res/android">
            <!-- your original selector content -->
        </selector>
    </item>
</layer-list>
like image 67
Oliv Avatar answered Nov 16 '22 02:11

Oliv