在android中的控件LinearLayout 中的android:gravity="center" 属性,要么是居左、居右、居中对齐,android:gravity="right" 和 android:gravity="left"并不能达到双控件的左右两端对齐,

要实现两端对齐方式,要采用 中间增加一个控件的方式实现 ,并设置属性android:layout_weight="1",原因是设置android:layout_weight="1",就把控件均分了

具体的布局文件如下:

Xml代码

  1. <?xmlversion="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">

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

  30. </Button>

  31. </LinearLayout>

效果如图:


实现两个button按钮 两端对齐


更多相关文章

  1. Android的常用基本控件ImageView、ListView
  2. Android(安卓)相对布局 RelativeLayout 属性 (转)
  3. Android(安卓)控件(button)对齐方法实现详解
  4. Android(安卓)控件布局常用属性
  5. android相对布局 相对对齐
  6. Android常见布局控件之LinearLayout和TableLayout
  7. Android(安卓)RelativeLayout 属性
  8. Android(安卓)RelativeLayout 属性
  9. Android之UI

随机推荐

  1. 模糊的身份證怎么P清楚清晰
  2. P身份證怎么在A4纸上打印
  3. CSS:圣杯布局例子-复习
  4. CSS:盒模型-复习
  5. WSL安装及配置图形界面
  6. 事件绑定、组件、路由实例演示
  7. 【精华】Android应用程序框架分析
  8. Android(安卓)studio使用Lottie- 让Andro
  9. Android的标题栏
  10. Android(安卓)编译环境配置搭建(Ubuntu 1