相对布局
相对布局
1.相对布局的简单使用:
相对布局(RelativeLayout)将子视图以相对位置显示。默认显示在父视图的左上角。
layout_alignParentTop,父视图的上边
layout_alignParentBottom,父视图的下边
layout_alignParentLeft,父视图的左边
layout_alignParentRight,父视图的右边
2.以下为.xml的主要内容:
显示四个大小相同颜色不同的长方形,通过相对布局来实现每个角有一个长方形。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
tools:context=".LXCMainActivity">
<RelativeLayout //相对布局
android:layout_width="match_parent"
android:layout_height="match_parent"