In Android, the Android: gravity = "center" attribute in the linearlayout is either left, right, or center. Android: gravity = "right" and Android: gravity = "Left" cannot align the left and right sides of the two controls,
To achieve the alignment between the two ends, add a control in the middle and set the property Android: layout_weight = "1" because Android: layout_weight = "1 ", the controls are evenly allocated.
The specific layout file is as follows:
XML Code 650) This. width = 650; "alt =" Copy code "src =" http://airshiplay.iteye.com/images/icon_copy.gif "/> 650) This. width = 650; "class =" star "alt =" add to favorites code "src =" http://airshiplay.iteye.com/images/icon_star.png "/> 650) This. width = 650; "class =" Spinner "src =" http://airshiplay.iteye.com/images/spinner.gif "alt =" spinner.gif "/>
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Android: layout_width = "match_parent"
Android: layout_height = "20dp"
Android: Background = "# efefef"
Android: Orientation = "horizontal">
<Button
Android: text = "button1"
Android: layout_marginleft = "4dp"
Android: Id = "@ + ID/btnlogin_main"
Android: layout_height = "20dp"
Android: layout_width = "wrap_content"
Android: textsize = "12dp"
Android: Background = "# efefef"
Android: textcolor = "#404040" type = "codeph" text = "/codeph">
</Button>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"/>
<Button
Android: Id = "@ + ID/btnsetting_main"
Android: layout_marginright = "4dp"
Android: layout_width = "wrap_content"
Android: layout_height = "20dp"
Android: text = "button2"
Android: textsize = "12dp"
Android: Background = "# efefef"
Android: textcolor = "#404040" type = "codeph" text = "/codeph">
</Button>
</Linearlayout>
Effect
650) This. width = 650; "src =" http://dl.iteye.com/upload/attachment/0083/7573/d3ede058-5301-3dbd-a232-f7344250435b.png "/>
Align two buttons
This article is from the "qytag (upspringing)" blog, please be sure to keep this source http://qytag.blog.51cto.com/6125308/1567763
Align left and right in the linearlayout Layout