ConstraintLayout wrap_content內(nèi)容超出邊界

image.png

如圖,我們的豎向textview在當前設(shè)置下,如果文字較多,并不會被約束在父布局中。

但如果我們加上對頂部的約束:

 app:layout_constraintTop_toTopOf="parent"

當字數(shù)變少的時候,又不能實現(xiàn)textview從底部開始的需求


image.png

這個時候就用上兩個屬性:

  app:layout_constrainedHeight="true"
  app:layout_constraintVertical_bias="1.0"
  • app:layout_constrainedHeight表示是否約束height,相應(yīng)的也有app:layout_constrainedWidth
  • app:layout_constraintVertical_bias表示作用于鏈頭第一個子控件,通過設(shè)置值0~1控制頭尾間距比例(偏移比例)

最后:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_gravity="center"
    android:background="#33bb"
    android:layout_height="400dp">

    <TextView
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:text="我要顯示在底部"
        android:textSize="15sp"
        android:layout_width="15dp"
        android:orientation="vertical"
        app:layout_constrainedHeight="true"
        app:layout_constraintVertical_bias="1.0"
        app:layout_constraintTop_toTopOf="parent"
        android:gravity="bottom"
        android:ellipsize="end"
        android:layout_height="wrap_content"/>

</android.support.constraint.ConstraintLayout>
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容