线性布局(LinearLayout)和相对布局(RelativeLayout)

LinearLayout

最外层水平布局,里边两个带文字的 线性布局LinearLayout

<LinearLayout 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="match_parent"
    tools:context=".MainActivity"
    android:orientation="horizontal">


    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="200dp"
        android:layout_height="100dp"
        android:background="#0FFF00"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="凌晨两点半"
            android:textSize="40sp">

        </TextView>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/ll_2"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#0FFFFF"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="凌晨两点半"
            android:textSize="40sp"
            >
            

        </TextView>
    </LinearLayout>
  

</LinearLayout>

在这里插入图片描述
在这里插入图片描述
通过id使得activity能够对控件进行操作
margin外边距
padding内边距
orientation本控件内子控件布局方式
background背景(可以是纯色,可以是图片)
width和height可以选择wrap-Content和match-content,前者表示内容有多少高度或者宽度就有多少,后者是匹配父控件的高度或者宽度。

RelativeLayout

android:layout_alignParentBottom相对父控件的位置放置(当然有其他方向的设置)

<RelativeLayout 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="match_parent"
    tools:context=".MainActivity"
    android:orientation="horizontal">

    <View
        android:id="@+id/view_1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000"
        android:layout_alignParentBottom="true"
        >

    </View>


</RelativeLayout>

在这里插入图片描述

将黑块2放在黑块1的右边
android:layout_toRightOf相对放置

 <View
        android:id="@+id/view_1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000"
        >

    </View>
    <View
        android:id="@+id/view_2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000000"
        android:layout_toRightOf="@id/view_1"
        >

    </View>

在这里插入图片描述
android:layout_below //在某元素的的下方;
android:layout_alignBottom//本元素的下边缘和某元素的的下边缘对齐;
android:layout_alignparentBottom//父容器底部

猜你喜欢

转载自blog.csdn.net/WA_MC/article/details/115387497
今日推荐