笔记74 | 笔记74 | 学习掌握ConstraintLayout的基本属性

最近一个礼拜业余时间都在搞我的淘宝店铺,有兴趣的都可搜一下:吉安车品,主营汽车脚垫/后备箱垫/座垫,还在打基础阶段,不急,慢慢搞,当业余爱好去买卖;
吃饭手艺功夫自然不能丢,为下个月的变数准备,今天开始复习/学习一些基础内容,今天的笔记是ConstraintLayout的几个属性。

1、Circular positioning(圆形定位)

标题后面的中文是自己翻译的,可能不是很准确。

官方文档是这么介绍的:

You can constrain a widget center relative to another widget center, at an angle and a distance. This allows you to position a widget on a circle

我是这么理解的,您可以将一个控件的中心以一定的角度和距离约束到另一个控件的中心,相当于在一个圆上放置一个控件。

示例代码如下:

<Button android:id="@+id/buttonA" ... />
  <Button android:id="@+id/buttonB" ...
      //引用的控件ID
      app:layout_constraintCircle="@+id/buttonA"
      //圆半径
      app:layout_constraintCircleRadius="100dp"
      //偏移圆角度  水平右方向为0逆时针方向旋转
      app:layout_constraintCircleAngle="45" />

效果图:

c_1

图文并茂,理解起来较容易些。圆形定位使用其他布局是很难实现的(除自定义外),该功能在实际的开发中用的并不多,可以用来实现类似钟表的效果。该功能只不过是约束布局的冰山一角,且往下看。

2、WRAP_CONTENT : enforcing constraints(强制约束)

官方文档是这么介绍的:

If a dimension is set to WRAP_CONTENT, in versions before 1.1 they will be treated as a literal dimension -- meaning, constraints will not limit the resulting dimension. While in general this is enough (and faster), in some situations, you might want to use WRAP_CONTENT, yet keep enforcing constraints to limit the resulting dimension. In that case, you can add one of the corresponding attribute

英文一直是我的弱项,我是这么理解的,1.1.0 版本之前是没有这个功能的,说的是控件的宽设置为 WRAP_CONTENT (包裹内容)时,如果实际宽度超过了约束的最大宽度,那么约束会失效(高同理),为了防止约束失效,增加了以下属性:

  • app:layout_constrainedWidth=”true|false” //默认false
  • app:layout_constrainedHeight=”true|false” //默认false

官网并没有过多说明,那么怎么去理解呢,接下来以app:layout_constrainedWidth属性来看两个例子。

a、例子

c_2

B 控件位于 A 控件右侧与屏幕右侧的中间。代码如下:

    <Button
        android:id="@+id/bt_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:text="A"
        app:layout_constraintLeft_toLeftOf="parent"/>

    <Button
       
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值