LinearLayout控件两端对齐
来源:互联网 发布:audition软件下载 编辑:程序博客网 时间:2024/06/04 19:59
方法一:
在android中的控件LinearLayout 中的android:gravity="center" 属性,要么是居左、居右、居中对齐,不能达到双控件 两端对齐,要实现两端对齐方式,要采用 中间增加一个控件的方式实现 ,并设置属性weight=1。
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp"> <TextView android:id="@+id/tv_name" style="@style/commanditem_name_tv"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" /> <com.dashuai.view.SwitchButton android:id="@+id/switch_com" style="@style/SwitchButtonStyle" android:layout_marginRight="10px"/> </LinearLayout>
方法二:
采用LinearLayout中包含另一个LinearLayout
在第二个linearLayout中放置需要右置的空间,同时将其对齐方式设为右对齐:android:gravity="right" 同时将LinearLayout的宽度设为充满父控件: android:layout_width="fill_parent"<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="可变要显示的文字" /> <!-- 下面到关键部分: 将最右边的的checkbox复选框控件单独放在另一个LinearLayout中 同时将其对齐方式设为右对齐:android:gravity="right" 同时将LinearLayout的宽度设为充满父控件: android:layout_width="fill_parent" --> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right" > <CheckBox <CheckBox android:id="@+id/item_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" /> </LinearLayout></LinearLayout>
参考:
http://blog.csdn.net/a78270528/article/details/49507205
http://jileniao.net/post-125.html
0 0
- LinearLayout控件两端对齐
- LinearLayout中的控件两端对齐
- LinearLayout中的控件两端对齐
- LinearLayout中的控件两端对齐
- LinearLayout中的控件两端对齐 或 Button、TextView左右对齐
- android控件两端对齐
- 使用LinearLayout做到充满并两端对齐显示
- LinearLayout下控件右对齐
- Android LinearLayout 子控件底部对齐
- 让LinearLayout中的控件可以右对齐
- LinearLayout中控件不能居右对齐
- LinearLayout中控件不能居右对齐
- Android TextView两端对齐、文本两端对齐
- css文字两端对齐
- css文字两端对齐
- CSS两端对齐
- 设置文字两端对齐
- 文字左右两端对齐
- orCAD和PADS联合电路设计
- GTK+图形化应用程序开发学习笔记(十二)—对话框构件、标尺构件
- EF 三层 BLL DAL
- 正则判断手机号
- mysql处理中文乱码的问题
- LinearLayout控件两端对齐
- LRU算法的实现
- java内存机制
- GTK+图形化应用程序开发学习笔记(十三)—微调构件
- JavaScript练习(三)简单的轮播器原理代码
- python模块的发布
- 文件的基本编译
- HDU3336-Count the string-KMP(next数组理解)
- 一种在线客服均衡分配的方法及装置