Issue
In my layout I have a button with a background image. When I set the width and height both to wrap_content
, the background gets stretched. But when I use the same value for dp
to set to width and height I get the expected result. Why is it happening?
The image is originally circle.
<Button
android:id="@+id/captureButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/custom_capture" />
When set to wrap content for height and width
When set to 80dp for height and width
Solution
Because background
is meant to fill the container.
But, since Button inherits from TextView, you can use a compound drawable.
Something like so:
<Button
android:id="@+id/captureButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/custom_capture"
/>
Alternative: Using a TextView
<TextView
android:id="@+id/captureButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/custom_capture"
android:clickable="true"
/>
Answered By - Phantômaxx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.