Android-ConstraintLayout使用笔记(二)

上一节说到一些常用的约束,以及一些功能按钮的使用,接下来将记录ConstraintLayout布局中的一些其他属性:

  1. 倾向:当一个控件在父控件位置处于居中位置时,我们可以设置:app:layout_constraintHorizontal_bias将其或左或右的倾向(垂直居中情况:app:layout_constraintVertical_bias上下倾向)
  • 水平倾向:
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name"
    app:layout_constraintLeft_toRightOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHorizontal_bias="0.3"/>

在这里插入图片描述

  • 垂直倾向:
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintVertical_bias="0.3"/>

在这里插入图片描述
2. 宽高比:在约束布局中出了一个app:layout_constraintDimensionRatio属性,用来约束宽高的比例,默认是:宽比高。此属性起作用的前提条件是,至少有一方(宽或者高)设置为0dp,并与其它控件产生相应的约束

<--不起作用情况,因为宽或高没有设置为0dp-->
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:text="@string/app_name"
    app:layout_constraintDimensionRatio="1:3"/>
    
<-- 宽比高:1:3 -->
<Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:text="@string/app_name"
    app:layout_constraintDimensionRatio="1:3"/>

当为宽高比例指定W或H关键字时:

// 宽比高,1:3
app:layout_constraintDimensionRatio="W,1:3"

// 高比宽,1:3
app:layout_constraintDimensionRatio="H,1:3"
  1. goneMargin属性:A,B,C三个控件,依次水平排列,C对B控件设置为goneMarginLeft="20dp"时,若B为visiable时,BC控件紧密挨着,若B为gone时,C距离A为20dp。B为invisible时,与visiable时位置一样。

在这里插入图片描述

上一节补充:

基线的使用:
  • 在这里插入图片描述所谓基线就是一条看不见的线,是使开发者便于添加约束的线。可以添加水平基线和垂直基线两种在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值