android:layout_height=“wrap_content”
android:text=“拉伸我要被要被拉伸我要被拉伸”
android:textSize=“20sp”
app:layout_constraintWidth_default=“wrap”
app:layout_constraintStart_toEndOf="@id/viewA"
app:layout_constraintEnd_toStartOf="@id/viewB"
app:layout_constraintTop_toTopOf=“parent”
/>
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RmsPLx7r-1638154247345)(https://user-gold-cdn.xitu.io/2019/11/14/16e69c175b8e3534?imageView2/0/w/1280/h/960/ignore-error/1)]
当指定为wrap模式,则会保留约束条件:
…
android:layout_width=“0dp”
app:layout_constraintWidth_default=“wrap”
…
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1zbx0bwi-1638154247371)(https://user-gold-cdn.xitu.io/2019/11/14/16e69c35ea94d831?imageView2/0/w/1280/h/960/ignore-error/1)]
另外,针对传统的WRAP_CONTENT
模式,约束布局有额外的属性,使得它也能保留约束条件:app:layout_constrainedWidth="true"
此时与wrap模式一样的效果。
3.1.3 percent模式
app:layout_constraintWidth_default="percent"
:以父布局的百分比作为自身的大小,即百分比布局。(利用次特性可解决部分常见适配),通过app:layout_constraintWidth_percent
设置比例大小,0f-1.0f
…
android:layout_width=“0dp”
app:layout_constraintWidth_default=“percent”
app:layout_constraintWidth_percent=“0.8”
…
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RgmJbRa8-1638154247372)(https://user-gold-cdn.xitu.io/2019/11/14/16e69ca990d05117?imageView2/0/w/1280/h/960/ignore-error/1)]
3.1.4 指定宽高比(ratio)
app:layout_constraintDimensionRatio
:约束布局还可以指定view自身宽高比例。
其值可以为“width:height”或者“width/height”,如宽是高的2倍:app:layout_constraintDimensionRatio="2:1"
或app:layout_constraintDimensionRatio="2"