3 回答

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個贊
標(biāo)準(zhǔn)的 Android 框架中沒有任何東西可以讓你這樣做,但是有一個來自 Google 的非常好的外部庫,叫做FlexboxLayout可以為你做這件事。
您將使用 aFlexboxLayout作為所有TextViews 的父級,而不是例如 a LinearLayout,它將負(fù)責(zé)為您包裝它們。
<com.google.android.flexbox.FlexboxLayout
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_height="match_parent"
app:flexWrap="wrap">
<!-- add your 20 textviews here -->
</com.google.android.flexbox.FlexboxLayout>
請注意,指定很重要,app:flexWrap="wrap"因?yàn)槟J(rèn)情況下不進(jìn)行包裝。我不確定為什么會這樣,因?yàn)槭褂眠@個庫的全部目的是為了包裝,但是嘿。

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個贊
使用高度作為 wrap_content 和寬度作為 match_parent 創(chuàng)建線性布局,然后在其中創(chuàng)建 Textview 并將其高度作為 wrap_content ,因此當(dāng)您的內(nèi)容增加時它會自動擴(kuò)展。就這么簡單。您可以查看下面的示例。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:singleLine="false"
android:textColor="@color/black"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
添加回答
舉報