相对布局要比前面讲的线性布局和表格布局要灵活一些,所以平常用得也是比较多的。相对布局控件的位置是与其周围控件的位置相关的,从名字可以看出来,这些位置都是相对的,确定出了其中一个控件的位置就可以确定另一个控件的位置了。
本次实验就是显示如下的activity:<TextView
android:id="@+id/input" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/input_dis" tools:context=".MainActivity" /> <EditText android:id="@+id/edit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/input" android:background="@android:drawable/editbox_background" /> <Button android:id="@+id/ok" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/edit" android:layout_alignParentRight="true" android:layout_marginLeft="10px" android:text="@string/ok" /> <Button android:id="@+id/cancel" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/edit" android:layout_toLeftOf="@id/ok" android:text="@string/cancel" /></RelativeLayout>
总结:activity的相对布局比较灵活,一些常见的属性也比较多,用得多自然就会了。 作者:tornadomeet
精彩评论