Android studio 布局LinearLayout,RelativeLayout,FrameLayout,GridLayout,ConstraintLayout

xml布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"(子控件处于竖直排列)
    android:gravity="center|bottom"(子控件的布局方式:居中且位于底部)
    android:divider="@drawable/black_line"(分割线采取的样式)
    android:showDividers="middle"(分割线出现在哪里)
    android:dividerPadding="90dp"(分割线的大小)
    >
<!--        vertical 是指布局竖直排序//horizontal 是水平排列-->

        <LinearLayout
            android:layout_weight="1"(在父控件中的权重)
            android:layout_gravity="left"(自身的布局方式)
            android:background="#ff0000"(背景颜色)
            android:layout_width="200dp"(控件宽度)
            android:layout_height="0dp"(控件高度)/>
        <View(绘制间隔线,它也是一种绘制间隔的方法)
            android:background="#f0f0"
            android:layout_width="wrap_content"
            android:layout_height="10dp"/>

        <LinearLayout
            android:layout_weight="1"
            android:layout_gravity="left"
            android:background="#fff000"
            android:layout_width="200dp"
            android:layout_height="0dp"/>
        <View
            android:background="#f0f0"
            android:layout_width="wrap_content"
            android:layout_height="10dp"/>

        <LinearLayout
            android:layout_weight="1"
            android:layout_gravity="left"
            android:background="#ff55f5"
            android:layout_width="200dp"
            android:layout_height="0dp"/>

</LinearLayout>

RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout(父容)
    android:padding="23dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout(子容器)
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentRight="true"(以父容器为坐标)
        android:layout_marginRight="234dp"(在父容器中的坐标)
        android:layout_above="@id/green"(以兄弟容器为坐标)
        android:background="#ff0000" />


    <RelativeLayout(子容器)
        android:id="@+id/green"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:background="#f0f0" />




</RelativeLayout>

FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <FrameLayout
        android:foreground="@drawable/boy"(设置前景)
        android:foregroundGravity="bottom|right"(设置前景的位置)
        android:background="#ff0000"
        android:layout_width="400dp"
        android:layout_height="400dp"/>

    <FrameLayout
        android:background="#f0f0"
        android:layout_width="300dp"
        android:layout_height="300dp"/>
    
</FrameLayout>

GridLayout

<?xml version="1.0" encoding="utf-8"?>
<GridLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="3"(每一行显示的可以分成几列,配合		    android:orientation="horizontal")
    android:rowCount="3"(每一列显示的可以分成几行,配合android:orientation="vertical")
    xmlns:android="http://schemas.android.com/apk/res/android">
    <Button
        android:text="第一个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />
    <Button
        android:text="第二个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_row="1"(位于第几列)
        android:layout_column="0"(位于第几行)
        android:layout_columnSpan="4"(占用几行)
        android:layout_gravity="fill"(元素内部填满)
        />

    <Button
        android:text="第三个"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_row="0"
        android:layout_column="1"
        android:layout_rowWeight="1"(占用空闲行的比重)
        />

    <Button
        android:text="第四个"
        android:layout_columnWeight="1"(占用空闲列的比重)
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />


</GridLayout>

ConstraintLayout布局:
约束布局:使用可视化布局;
十分方便高效;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值