Issue
I have a drawableStart
icon drawable in my Button
below but it doesn't scale correctly. What can i do to correct this?
<Button
android:id="@+id/show_in_map_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:background="@drawable/round_details_button"
android:drawableStart="@drawable/location_btn"
android:drawableTint="@android:color/white"
android:fontFamily="@font/montserrat_medium"
android:paddingStart="15dp"
android:paddingEnd="15dp"
android:text="@string/show_in_map_button"
android:textColor="@android:color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/place_description" />
P.S: I've seen a few posts regarding this issue that attempted to solve it in code using ScaleDrawable
, but that didn't work for me.
Solution
There is an old approach that works for me.
I simply create bounds and set it to my button. This way any drawable I attach to my drawable takes the dimension of the bounds.
drawable.bounds = Rect(0, 0, 80, 80) // in this case, the drawable is going to be 80 x 80
button.setCompoundDrawables(drawable, null, null, null)
I hope this helps. Merry coding!
Answered By - Taslim Oseni
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.