Tuesday, March 19, 2013

[android-developers] Setting density-specific drawable as button background

I have a few buttons in my application that don't have any text, only background drawable. I need to make it so that the drawable is taken from an appropriate drawable-?dpi folder, and then displayed without resizing. The first part works, the appropriate image file is selected. However, it is still resized no matter what layout_height and layout_width attributes the button has. My question is: how to defeat this, and make drawables map to screen pixel-to-pixel?

The only way I can make it not to resize is to specify width and height in px, which is exactly what I don't want to do.

Here's what my layout looks like:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools">

    <LinearLayout

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RelativeLayout

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="3dp"
            android:paddingTop="3dp" >

            <Button

                android:id="@+id/btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/btn" />

        </RelativeLayout>

    </LinearLayout>

</ScrollView>

P. S. Is there any way to create a file similar to "dimensions.xml" in which I could define px sizes of my drawable for different DPI screens? I already have "dimensions.xml" for large and normal screens

--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment