Align left and right in the linearlayout Layout

Source: Internet
Author: User

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 "/>

  1. <? XML version = "1.0" encoding = "UTF-8"?>

  2. <Linearlayout

  3. Android: layout_width = "match_parent"

  4. Android: layout_height = "20dp"

  5. Android: Background = "# efefef"

  6. Android: Orientation = "horizontal">

  7. <Button

  8. Android: text = "button1"

  9. Android: layout_marginleft = "4dp"

  10. Android: Id = "@ + ID/btnlogin_main"

  11. Android: layout_height = "20dp"

  12. Android: layout_width = "wrap_content"

  13. Android: textsize = "12dp"

  14. Android: Background = "# efefef"

  15. Android: textcolor = "#404040" type = "codeph" text = "/codeph">

  16. </Button>

  17. <Textview

  18. Android: layout_width = "wrap_content"

  19. Android: layout_height = "wrap_content"

  20. Android: layout_weight = "1"/>

  21. <Button

  22. Android: Id = "@ + ID/btnsetting_main"

  23. Android: layout_marginright = "4dp"

  24. Android: layout_width = "wrap_content"

  25. Android: layout_height = "20dp"

  26. Android: text = "button2"

  27. Android: textsize = "12dp"

  28. Android: Background = "# efefef"

  29. Android: textcolor = "#404040" type = "codeph" text = "/codeph">

  30. </Button>

  31. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.