关于Android 相对布局中的属性 的介绍和运用
16lz
2021-01-23
相对布局中的属性的运用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <!-- RelativeLayout:相对布局;子控件相对父容器;子控件相对兄弟控件 --> <!-- 相对属性不设置控件默认位置在父容器左上角 --> <!-- 子控件相对父容器属性: --> <!-- layout_alignParentRight:相对于父容器右侧 --> <!-- layout_alignParentBottom:相对于父容器底部 --> <!-- layout_alignParentLeft:相对于父容器左侧 --> <!-- layout_alignParentTop:相对于父容器顶部 --> <!-- layout_centerInParent:垂直水平居中 --> <!-- layout_centerVertical:垂直居中 --> <!-- layout_centerHorizontal:水平居中 --> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentRight="true" android:background="#000fff" android:text="right|top" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentBottom="true" android:background="#fff000" android:text="left|bottem" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true" android:background="#000fff" android:text="Left|Top" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="#fff000" android:text="right|bottem" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_centerInParent="true" android:background="#f0f0f0" android:text="center" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:background="#0f0f0f" android:text="top|horizontal" android:textColor="#ffffff" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:background="#00ffff" android:text="left|vertical" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="#fffff0" android:text="right|vertical" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="#fff000" android:text="bottem|horizontal" /></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- id:使用具体控件前提:@+id/在给控件声明新id时使用;@id/使用已有的id --> <!-- layout_toLeftOf:在哪个兄弟控件的左侧 --> <!-- layout_toRightOf:在哪个兄弟控件的右侧 --> <!-- layout_above:在哪个兄弟控件的上边 --> <!-- layout_below:在兄弟控件下边 --> <TextView android:id="@+id/centerTv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#000fff" android:text="center" android:textColor="#ffffff" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@id/centerTv" android:text="left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/centerTv" android:text="right" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/centerTv" android:layout_centerHorizontal="true" android:text="top" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/centerTv" android:layout_centerHorizontal="true" android:text="bottem" /></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- layout_alignLeft:相对于兄弟控件左对齐 --> <!-- layout_alignRight:相对于兄弟控件右对齐 --> <!-- layout_alignTop:相对于兄弟控件顶部对齐 --> <!-- layout_alignBottom:相对于兄弟控件底部对齐 --> <TextView android:id="@+id/centerTv" android:layout_width="50dp" android:layout_height="50dp" android:layout_centerInParent="true" android:background="#00ffff" android:text="center" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/centerTv" android:text="left" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignRight="@id/centerTv" android:text="right" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/centerTv" android:text="bottem" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@id/centerTv" android:text="top" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@id/centerTv" android:layout_toRightOf="@id/centerTv" android:text="base" /></RelativeLayout>
更多相关文章
- Android UI控件详解-SeekBar(拖动条)
- Android UI控件详解-GridView(网格视图)
- android之布局xml各种控件属性详解
- android的一款日期选择控件
- android之SeekBar控件用法
- android EditText控件设置只读
- Android ListView 控件学习
- ScrollView里面放入多个子控件
- Android开发UI之自定义控件的皮肤