Lara
Lara

Reputation: 172

Button with background image is not shown proportionately

Here is my button image file from my drawable folder called ooo.png:

enter image description here

And that's how it looks like on the device:

enter image description here

As you can see the width height proportion changed. It's a bit wider than the original. I need it to be looking the same though.

I don't understand what causes this stretching. Here is my xml-file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
        <Button
            android:id="@+id/button1"
            style="@style/styleBtns"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="50dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

</LinearLayout>

My styleBtns-part of the styles.xml:

    <style name="styleBtns" >
        <item name="android:background">@drawable/btns_abc</item>

    </style>

And in my btns_abc I set the background to my image resource. Currently state pressed and the normal state are the same, I want to change that as soon as it works properly:

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

</selector>

Thanks !

Upvotes: 0

Views: 42

Answers (1)

Manmohan Badaya
Manmohan Badaya

Reputation: 2336

I don't know the exact reason but for a solution if u don't have any text for button ,use ImageView will show the same drawable u have added.

Upvotes: 1

Related Questions