相对布局
来源:互联网 发布:大数据的稀疏性 编辑:程序博客网 时间:2024/04/27 20:42
相对布局是android应用中最为常用的布局。
相对布局非常实用,可把控件放简单轻松地放到你想放置的位置:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/tx1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#ff0000" android:width="80dp" android:height="80dp" android:layout_centerInParent="true" /> <TextView android:id="@+id/tx2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#990000" android:width="60dp" android:height="60dp" android:layout_toLeftOf="@id/tx1" />这里的代码的意思是先把第一个TextView放到屏幕的中央,然后第二个TextView位于第一个组件的左侧,相对布局中有很多相对于组件位置的属性,所以我们可以根据需要设置组件的位置,非常方便。
0 0