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

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

具体的布局文件如下:

Xml代码 复制代码收藏代码spinner.gif

  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 控件(button)对齐方法实现详解
  2. Kotlin 写 Android 单元测试(四),Robolectric 在 JVM 上测试安卓相
  3. Android常见布局控件之LinearLayout和TableLayout
  4. Android开发——控件基础(三)EditText组件以及简单的登录界面
  5. Android项目打包、Eclipse视图和UI控件
  6. 修改 framework 代码的经验和踩过的坑

随机推荐

  1. 21个php常用方法汇总
  2. php如何整合qq互联登录
  3. PHP实现手机网站支付(兼容微信浏览器)
  4. PHP自定义的 printf 函数新用途
  5. 我们还会继续使用PHP的原因
  6. 简易实现HTTPS之自动实现ssl
  7. 总结PHP-FPM与Nginx的通信机制
  8. PHP中如何使用TUS协议来实现大文件的断点
  9. 何为是高性能优化PHP-FPM
  10. PHP+MySQL实现在线测试答题示例