How to center drawableTop and text vertically on the Button in Android?
Posted
by Gaks
on Stack Overflow
See other posts from Stack Overflow
or by Gaks
Published on 2010-04-15T10:50:14Z
Indexed on
2010/04/15
10:53 UTC
Read the original article
Hit count: 243
I have the Button defined as follows:
<Button
android:drawableTop="@drawable/ico"
android:gravity="center"
android:id="@+id/StartButton2x2"
android:text="@string/Widget2x2StartBtnLabel"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/widgetbtn_bg"
/>
The problem is that 'drawableTop' image is aligned to the top border of the Button view. I would like to center it (together with text label) vertically on the button.
'android:gravity' seems to work only on text label. It does not affect 'drawableTop' positioning.
I was able to center it vertically using 'android:paddingTop' - but that does not seem to be a good idea. I guess it would not work properly on different screen resolution/size.
© Stack Overflow or respective owner