How to set text set on center position when using DrawableLeft on a button?
<Button
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:background="@drawable/rectangle_round_white"
android:drawableLeft="@drawable/icon_google"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:elevation="5dp"
android:text="start with google"
android:textAlignment="center"
android:textSize="11dp"/>
the text 'START WITH GOOGLE' is not placed on center. How to center it?
CodePudding user response:
There is no built-in way to do this with just a Button
. You could wrap everything in a ViewGroup
of some sort or you could simply adjust the paddings until you're happy with the result. I prefer the padding method.
CodePudding user response:
One hacky solution is to make a transparent png file or the same color as the background with the exact dimensions of icon_google
and set it as drawableRight like so:
<Button
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:background="@drawable/rectangle_round_white"
android:drawableLeft="@drawable/icon_google"
android:drawableRight="@drawable/transparent_icon_google"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:elevation="5dp"
android:text="start with google"
android:textAlignment="center"
android:textSize="11dp"/>
CodePudding user response:
This move to linierleyout
and you have drawebelPadinge