1:LinearLayput 线性布局
线性布局中设置控件一个居左一个居右,设置一个控件用于占位,设置这个控件 的权重为1,。具体你代码如下
<LinearLayout
android:background="@color/color_ffe89a"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:gravity="center_vertical"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:text="注册"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
2:RelativeLayout 相对布局
相对布局设置一个控件为自包裹,另一个控件占据剩下的所有位置,为另一个控件设置他的宽度的math_parent,代码如下
<RelativeLayout
android:background="@color/orange"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/left"
android:text="左边"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:background="@color/colorf5"
android:gravity="center"
android:layout_toRightOf="@+id/left"
android:text="右边"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
原文:http://www.cnblogs.com/nbls/p/7253972.html