Android button or TextView vertical align
i am trying to vertically align a button or a textview, but i can't.
Neither android:layout_gravity="center_vertical|cen开发者_高级运维ter_horizontal"
nor android:gravity="center_vertical|center_horizontal"
works. Not even android:gravity="center"
does the trick.
They only aligns the object horizontally. How can i align it to the center or bottom of the view?
Depends on the parent layout. If you're using a RelativeLayout, you can simply use layout_alignParentBottom="true"
, although layout_gravity="bottom"
should work as well. Keep in mind the size of this parent layout as well. You can't use alignParentBottom
if the RelativeLayout is set to wrap_content
for height. It should be set to fill_parent
. You should post the rest of your XML if you're still having issues.
精彩评论