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