android:layout_alignleft layout_toleftof区别,详解RelativeLayout布局属性
2017-11-02 11:32
429 查看
原文地址:http://blog.csdn.net/qq_32059827/article/details/51488016
最近看博客看到有关于RelativeLayout布局的解释,有的解释很多是错误的。因此有必要对每一个常见的布局属性进行描述。以下解释全部都是逐行进行测试的。
[html] view plain copyprint? 首先把常用的布局分组。(会对所有的对其方式解释,且主要讨论layout_alignleft layout_toleftof区别)
android:layout_above 将该控件的底部至于给定ID的控件之上(只写一行代该控件底部与id控件上边缘对其,且默认于父布局左边)
android:layout_below 将该控件的顶部至于给定ID的控件之下(只写一行代该控件顶部与id控件下边缘对其,且默认于父布局左边)
android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐,默认是位于父布局的顶部
android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐,默认位于父布局的顶部
(默认父布局的左和上)
android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline对齐
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘对其(该控件还是默认位于父布局的左边)
android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐(该控件还是默认位于父布局的左边)效果和上边一样
android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐(该控件默认位于父布局的上边)
android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐(该控件默认位于父布局的上边)此时效果和上边效果一样
(默认父布局的左和上) android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐(只写一行默认左下)
android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐(只写一条默认左上)
android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐(默认右上)
android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐(只写一条默认左上)
(默认父布局的左和上)
android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央(默认父布局的上方)
android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央(默认父布局的左边)
显然layout_alignleft layout_toleftof区别就一目了然。通过代码和图片再一次视觉上区分:
首先看layout_aliginleft:
[html] view plain copyprint?<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"
4000
tools:context="com.itheima.helloworld.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="button1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/button1"
android:text="button2"
/>
</RelativeLayout>
图片:
![](https://img-blog.csdn.net/20160524131813508?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
再来看layout_toleftof代码如下:
[html] view plain copyprint?<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="com.itheima.helloworld.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="button1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/button1"
android:text="button2"
/>
</RelativeLayout>
图片如下:
![](https://img-blog.csdn.net/20160524132051542?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
对于相对布局的基本用法,应该一目了然。
最近看博客看到有关于RelativeLayout布局的解释,有的解释很多是错误的。因此有必要对每一个常见的布局属性进行描述。以下解释全部都是逐行进行测试的。
[html] view plain copyprint? 首先把常用的布局分组。(会对所有的对其方式解释,且主要讨论layout_alignleft layout_toleftof区别)
android:layout_above 将该控件的底部至于给定ID的控件之上(只写一行代该控件底部与id控件上边缘对其,且默认于父布局左边)
android:layout_below 将该控件的顶部至于给定ID的控件之下(只写一行代该控件顶部与id控件下边缘对其,且默认于父布局左边)
android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐,默认是位于父布局的顶部
android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐,默认位于父布局的顶部
(默认父布局的左和上)
android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline对齐
android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘对其(该控件还是默认位于父布局的左边)
android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐(该控件还是默认位于父布局的左边)效果和上边一样
android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐(该控件默认位于父布局的上边)
android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐(该控件默认位于父布局的上边)此时效果和上边效果一样
(默认父布局的左和上) android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐(只写一行默认左下)
android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐(只写一条默认左上)
android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐(默认右上)
android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐(只写一条默认左上)
(默认父布局的左和上)
android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央(默认父布局的上方)
android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央
android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央(默认父布局的左边)
首先把常用的布局分组。(会对所有的对其方式解释,且主要讨论layout_alignleft layout_toleftof区别) android:layout_above 将该控件的底部至于给定ID的控件之上(只写一行代该控件底部与id控件上边缘对其,且默认于父布局左边) android:layout_below 将该控件的顶部至于给定ID的控件之下(只写一行代该控件顶部与id控件下边缘对其,且默认于父布局左边) android:layout_toLeftOf 将该控件的右边缘和给定ID的控件的左边缘对齐,默认是位于父布局的顶部 android:layout_toRightOf 将该控件的左边缘和给定ID的控件的右边缘对齐,默认位于父布局的顶部 (默认父布局的左和上) android:layout_alignBaseline 该控件的baseline和给定ID的控件的baseline对齐 android:layout_alignBottom 将该控件的底部边缘与给定ID控件的底部边缘对其(该控件还是默认位于父布局的左边) android:layout_alignTop 将给定控件的顶部边缘与给定ID控件的顶部对齐(该控件还是默认位于父布局的左边)效果和上边一样 android:layout_alignLeft 将该控件的左边缘与给定ID控件的左边缘对齐(该控件默认位于父布局的上边) android:layout_alignRight 将该控件的右边缘与给定ID控件的右边缘对齐(该控件默认位于父布局的上边)此时效果和上边效果一样 (默认父布局的左和上) android:alignParentBottom 如果该值为true,则将该控件的底部和父控件的底部对齐(只写一行默认左下) android:layout_alignParentLeft 如果该值为true,则将该控件的左边与父控件的左边对齐(只写一条默认左上) android:layout_alignParentRight 如果该值为true,则将该控件的右边与父控件的右边对齐(默认右上) android:layout_alignParentTop 如果该值为true,则将空间的顶部与父控件的顶部对齐(只写一条默认左上) (默认父布局的左和上) android:layout_centerHorizontal 如果值为真,该控件将被至于水平方向的中央(默认父布局的上方) android:layout_centerInParent 如果值为真,该控件将被至于父控件水平方向和垂直方向的中央 android:layout_centerVertical 如果值为真,该控件将被至于垂直方向的中央(默认父布局的左边)
显然layout_alignleft layout_toleftof区别就一目了然。通过代码和图片再一次视觉上区分:
首先看layout_aliginleft:
[html] view plain copyprint?<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"
4000
tools:context="com.itheima.helloworld.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="button1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/button1"
android:text="button2"
/>
</RelativeLayout>
<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="com.itheima.helloworld.MainActivity"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="button1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/button1" android:text="button2" /> </RelativeLayout>
图片:
再来看layout_toleftof代码如下:
[html] view plain copyprint?<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="com.itheima.helloworld.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="button1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/button1"
android:text="button2"
/>
</RelativeLayout>
<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="com.itheima.helloworld.MainActivity"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="button1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/button1" android:text="button2" /> </RelativeLayout>
图片如下:
对于相对布局的基本用法,应该一目了然。
相关文章推荐
- android:layout_alignleft layout_toleftof区别,详解RelativeLayout布局属性
- android:layout_alignleft layout_toleftof 使用,详解RelativeLayout布局属性 ,搜索xm布局
- android:layout_alignleft layout_toleftof区别详解
- android:layout_alignleft layout_toleftof区别,详解RelativeLayout布局属性
- android:layout_alignleft layout_toleftof区别,详解RelativeLayout布局属性
- 在代码中设置RelativeLayout布局中标签的android:layout_toLeftOf、android:layout_toRightOf等属性
- 在代码中设置RelativeLayout布局中标签的android:layout_toLeftOf、android:layout_toRightOf等属性
- RelativeLayout用android:layout_toLeftOf后,控件不显示
- 关于Android Studio使用layout_toLeftOf这种相对布局属性时报错 , 找不到id和R文件的错误
- android:layout_alignLeft=""和android:layout_toLeftOf=""
- android 动态调整RelativeLayout布局控件的相对位置 layout_toLeftOf 之类的
- android属性layout_toRightOf和layout_toEndOf的区别
- android之layout_toLeftOf和layout_toRightOf出现的错误
- Android (layout_toLeftOf,layout_toRightOf,layout_above,layout_below) 使用注意点
- Android 布局详解 -三表格布局(TableLayout)以及重要属性
- 详解 android layout布局属性
- Android基础之LinearLayout与RelativeLayout的布局属性
- layout layout_alignLeft跟layout_toLeftOf
- Android布局属性详解之RelativeLayout