android - Why button is not centered vertically in LinearLayout? -
I have a LinearLayout, which has only one button, I want this button to stand and combine right. I tried several ways, but I could not concentrate this button vertically. It always combines at the top, I also tried to put a button in the relational layout, the button can not be even vertical.
Is XML down there is something wrong with this layout? Thank you.
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "Vertical" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: background = "#E8E3E4 "& Gt; & Lt; Button Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "and" android: layout_gravity = "right" /> & Lt; / LinearLayout & gt; Android: layout_gravity = "right" to android: layout_gravity = "right | center_vertical" has not solved the problem in my question.
In the words you say that you want to center it vertically, but you have not XML that you want it to be centered in the center. You'll need to adjust your android: layout_gravity
attribute to specify both correct
and center_vertical
. However, I would recommend that you go back to relative layout
. Use the android: layout_centerVertical = "true"
and android: layout_alignParentRight = "true"
buttons to be vertical and right align.
Also note that in your current LinearLayout
android: layout_height = "wrap_content" means, that means something in the inside Not even there. If you want to focus any meaning, then its container needs to get more space than its content (e.g., fill_parent
).
Comments
Post a Comment