android的布局文件简介

LinearLayout-线性布局:

LinearLayout-线性布局有两个方向:水平和垂直方向。分别是通过android:orientation="horizontal"和android:orientation="vertical"来控制的

权重,也就是对控件设置 android:layout_weight的属性。这个属性的意思是分配剩余空间

比如有俩个控件,分别设置为android:layout_weight=“1”,android:layout_weight=“2”,表示控件分别占屏幕的1/3和2/3,。不过这是有一个前提的,就是建立在控件的宽度或者高度设置为0dp的情况下。

例子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity" >
    <!-- android:orientation="vertical" 一定要写到头文件中,不然会出错-->
    <!--第一个例子是垂直布局,第二个例子是横向布局-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#120ff0" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#950ff0" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#079ff0" />
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000fca" />
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000f65" />
    </LinearLayout>
</LinearLayout >

RelativeLayout-相对布局

相对,顾名思义是有参照的,就是以某个兄弟组件,或者父容器来决定的(兄弟组件是在一个同一个布局里面的组件,如果是布局里一个组件参照另一个布局里的组件会出错)

android:paddingBottom:设置控件内容与控件下边缘的距离

android:paddingTop:设置控件内容与控件上边缘的距离

android:paddingLeft:设置控件内容与控件左边缘的距离

android:paddingRight:设置控件内容与控件右边缘的距离

android:layout_marginBottom:设置此控件的下边缘与其他控件的距离

android:layout_marginTop:设置此控件的上边缘与其他控件的距离

android:layout_marginLeft:设置此控件的左边缘与其他控件的距离

android:layout_marginRight:设置此控件的右边缘与其他控件的距离

 

ConstraintLayout(约束布局)

ConstraintLayout 能够灵活地定位和调整子View的大小,子 View 依靠约束关系来确定位置。

功能:

  • 相对定位 (横向:Left、Right、Start、End   ;纵向:Top、Bottom、Baseline(文本底部的基准线))
  • 外边距
  • 居中和倾向
  • 可见性的表现
  • 尺寸约束
  • Chain
  • 辅助工具

一些基本属性:

 

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值