top、bottom、left、right顾名思义为内部控件居顶、低、左、右布局。
这里要与android:layout_gravity区分开,layout_gravity是用来设置自身相对于父元素的布局。
android:layout_weight:权重,用来分配当前控件在剩余空间的大小。
使用权重一般要把分配该权重方向的长度设置为零,比如在水平方向分配权重,就把width设置为零。
先来看一下效果:
下面来看看代码:
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:id="@+id/LinearLayout1"
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”
tools:context=" r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}" >
<EditText
android:id="@+id/edit"
android:layout_width=“match_parent”
android:layout_height=“wrap_content” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal”
android:gravity=“center” >
<Button
android:id="@+id/button"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“确定”/>
<Button
android:id="@+id/button1"
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“取消” />
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal” >
<TextView
android:layout_width=“wrap_content”
android:layout_height=“200dp”
android:layout_weight=“1”
android:background="#ff0000"
android:text=“红色”/>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“200dp”
android:layout_weight=“1”
android:background="#00ff00"
android:text=“绿色”/>
<TextView