3 回答

TA贡献1788条经验 获得超4个赞
标准的 Android 框架中没有任何东西可以让你这样做,但是有一个来自 Google 的非常好的外部库,叫做FlexboxLayout可以为你做这件事。
您将使用 aFlexboxLayout作为所有TextViews 的父级,而不是例如 a LinearLayout,它将负责为您包装它们。
<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"因为默认情况下不进行包装。我不确定为什么会这样,因为使用这个库的全部目的是为了包装,但是嘿。

TA贡献2065条经验 获得超14个赞
使用高度作为 wrap_content 和宽度作为 match_parent 创建线性布局,然后在其中创建 Textview 并将其高度作为 wrap_content ,因此当您的内容增加时它会自动扩展。就这么简单。您可以查看下面的示例。
<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>
添加回答
举报