Search code examples
androidxmlandroid-layoutresizedrawable

Combined text- and image-button, resizing drawable


I have a button that I've implemented in one of my activities in my Android project - the button is supposed to contain both a logo (a drawable) and some text following it, but I have a very peculiar problem. In the preview-view of my activity xml-file, the button looks perfectly fine but when I run my app on my phone it gets absurdly large.

I import the drawable from an .xml drawable that I've myself have made. I tried imported a .png straight into my activity but it was too large - so I make a new xml where I resize it and that xml is what I import as my drawable. Code:

Activity.xml

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/title_activity_facebookInvite"
    android:id="@+id/btnInviteFacebook"
    android:layout_alignParentBottom="false"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/mainActivityInviteText"
    android:background="@drawable/bh_red_button"
    android:layout_marginTop="@dimen/bh_input_element_margin"
    android:textSize="@dimen/bh_button_font_size"
    android:drawableLeft="@drawable/fb_resize"
    android:layout_marginLeft="45dp"
    android:layout_marginRight="45dp"
    android:minHeight="0dp" />

fb_resize.xml (My drawable)

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

<item
    android:id="@+id/fb_resizeBtn"
    android:drawable="@mipmap/fb_logo"
    android:width="15dp"
    android:height="15dp"
    />

</layer-list>

fb_logo is my PNG that I've made. Another very strange thing is that when I emulate it on a virtual device in Android Studio it looks perfectly fine, but not on my phone (Have tried a different phone aswell).


Solution

  • Solved it! Instead of a .png I used a vector-picture (.svg file) and that resized just fine for some reason.