2022-05-07 ConstraintLayout子控件使用minHeight踩坑

1.異常模式代碼和效果圖
image.png
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="vertical">

  <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/clTop"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TextView
      android:id="@+id/tv1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/vLine1"
      app:layout_constraintHorizontal_weight="1.1"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv1" />

    <View
      android:id="@+id/vLine1"
      android:layout_width="0.5dp"
      android:layout_height="0dp"
      android:background="#E2E4EC"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/tv2"
      app:layout_constraintStart_toEndOf="@id/tv1"
      app:layout_constraintTop_toTopOf="parent"
      tools:background="@color/red" />

    <TextView
      android:id="@+id/tv2"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/vLine2"
      app:layout_constraintHorizontal_weight="1.1"
      app:layout_constraintStart_toEndOf="@id/vLine1"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv2" />

    <View
      android:id="@+id/vLine2"
      android:layout_width="0.5dp"
      android:layout_height="0dp"
      android:background="#E2E4EC"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/tv3"
      app:layout_constraintStart_toEndOf="@id/tv2"
      app:layout_constraintTop_toTopOf="parent"
      tools:background="@color/red" />

    <TextView
      android:id="@+id/tv3"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/vLine3"
      app:layout_constraintHorizontal_weight="3"
      app:layout_constraintStart_toEndOf="@id/vLine2"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv3" />

    <View
      android:id="@+id/vLine3"
      android:layout_width="0.5dp"
      android:layout_height="0dp"
      android:background="#E2E4EC"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/tv4"
      app:layout_constraintStart_toEndOf="@id/tv3"
      app:layout_constraintTop_toTopOf="parent"
      tools:background="@color/red" />

    <TextView
      android:id="@+id/tv4"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_weight="1.1"
      app:layout_constraintStart_toEndOf="@id/vLine3"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv4tv4tv4tv4tv4tv4tv4tv4tv4tv4" />
  </androidx.constraintlayout.widget.ConstraintLayout>

  <View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="@color/c_E2E4EC"
    app:layout_constraintTop_toBottomOf="@id/clTop"
    tools:background="@color/red" />
</LinearLayout>
2.正常模式代碼和效果圖
image.png
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="vertical">

  <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/clTop"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TextView
      android:id="@+id/tv1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/vLine1"
      app:layout_constraintHorizontal_weight="1.1"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv1" />

    <View
      android:id="@+id/vLine1"
      android:layout_width="0.5dp"
      android:layout_height="0dp"
      android:background="#E2E4EC"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/tv2"
      app:layout_constraintStart_toEndOf="@id/tv1"
      app:layout_constraintTop_toTopOf="parent"
      tools:background="@color/red" />

    <TextView
      android:id="@+id/tv2"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/vLine2"
      app:layout_constraintHorizontal_weight="1.1"
      app:layout_constraintStart_toEndOf="@id/vLine1"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv2" />

    <View
      android:id="@+id/vLine2"
      android:layout_width="0.5dp"
      android:layout_height="0dp"
      android:background="#E2E4EC"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/tv3"
      app:layout_constraintStart_toEndOf="@id/tv2"
      app:layout_constraintTop_toTopOf="parent"
      tools:background="@color/red" />

    <TextView
      android:id="@+id/tv3"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/vLine3"
      app:layout_constraintHorizontal_weight="3"
      app:layout_constraintStart_toEndOf="@id/vLine2"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv3" />

    <View
      android:id="@+id/vLine3"
      android:layout_width="0.5dp"
      android:layout_height="0dp"
      android:background="#E2E4EC"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toStartOf="@id/tv4"
      app:layout_constraintStart_toEndOf="@id/tv3"
      app:layout_constraintTop_toTopOf="parent"
      tools:background="@color/red" />

    <TextView
      android:id="@+id/tv4"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:minHeight="38dp"
      android:textColor="@color/gray_444444"
      android:textSize="14sp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_weight="1.1"
      app:layout_constraintStart_toEndOf="@id/vLine3"
      app:layout_constraintTop_toTopOf="parent"
      tools:text="tv4tv4tv4tv4tv4tv4tv4tv4tv4tv4" />
  </androidx.constraintlayout.widget.ConstraintLayout>

  <View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="@color/c_E2E4EC"
    app:layout_constraintTop_toBottomOf="@id/clTop"
    tools:background="@color/red" />
</androidx.constraintlayout.widget.ConstraintLayout>
3.問(wèn)題說(shuō)明

原本想整個(gè)Item按照內(nèi)容高度自適應(yīng)谚赎,但是在LinearLayout嵌套ConstraintLayout時(shí)會(huì)出現(xiàn)無(wú)法按照自己想要的高度適配适荣,但是改為ConstraintLayout嵌套ConstraintLayout后就好了零院,原理暫時(shí)沒(méi)有深究抓于,只是發(fā)現(xiàn)這樣可以解決

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市辅甥,隨后出現(xiàn)的幾起案子慌植,更是在濱河造成了極大的恐慌闯割,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,589評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件省店,死亡現(xiàn)場(chǎng)離奇詭異嚣崭,居然都是意外死亡笨触,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,615評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門(mén)雹舀,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)芦劣,“玉大人,你說(shuō)我怎么就攤上這事说榆⌒橐鳎” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,933評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵签财,是天一觀的道長(zhǎng)串慰。 經(jīng)常有香客問(wèn)我,道長(zhǎng)唱蒸,這世上最難降的妖魔是什么邦鲫? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,976評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮神汹,結(jié)果婚禮上庆捺,老公的妹妹穿的比我還像新娘。我一直安慰自己屁魏,他們只是感情好滔以,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,999評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著氓拼,像睡著了一般你画。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上桃漾,一...
    開(kāi)封第一講書(shū)人閱讀 51,775評(píng)論 1 307
  • 那天坏匪,我揣著相機(jī)與錄音,去河邊找鬼呈队。 笑死剥槐,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的宪摧。 我是一名探鬼主播粒竖,決...
    沈念sama閱讀 40,474評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼几于!你這毒婦竟也來(lái)了蕊苗?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,359評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤沿彭,失蹤者是張志新(化名)和其女友劉穎朽砰,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,854評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡瞧柔,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,007評(píng)論 3 338
  • 正文 我和宋清朗相戀三年漆弄,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片造锅。...
    茶點(diǎn)故事閱讀 40,146評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡撼唾,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出哥蔚,到底是詐尸還是另有隱情倒谷,我是刑警寧澤,帶...
    沈念sama閱讀 35,826評(píng)論 5 346
  • 正文 年R本政府宣布糙箍,位于F島的核電站渤愁,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏深夯。R本人自食惡果不足惜抖格,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,484評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望塌西。 院中可真熱鬧他挎,春花似錦、人聲如沸捡需。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,029評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)站辉。三九已至,卻和暖如春损姜,著一層夾襖步出監(jiān)牢的瞬間饰剥,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,153評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工摧阅, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留汰蓉,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,420評(píng)論 3 373
  • 正文 我出身青樓棒卷,卻偏偏與公主長(zhǎng)得像顾孽,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子比规,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,107評(píng)論 2 356

推薦閱讀更多精彩內(nèi)容