几周来我一直在尝试为此寻找解决方案,并一直将其放在我的待办事项列表中,但我无法包装 LinearLayout
的高度。
我有一个简单的线性布局
<LinearLayout
android:id="@+id/tagsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
android:paddingRight="10dp"
android:paddingBottom="5dp"
android:padding="5dp"/>
然后我使用我的代码将多个 TextViews
添加到具有标签链接样式的 LinearLayout
Txt.SetBackgroundResource(Resource.Drawable.roundtext);
Txt.SetPadding(30, 10, 30, 10);
Txt.SetTextColor(global::Android.Graphics.Color.ParseColor("#373944"));
Txt.SetTextSize(Android.Util.ComplexUnitType.Dip, 12);
看到最后一个 TextView 永远不会转到下一行
我查找了很多线程和解决方案,结果发现 LinearLayout
无法像这样包装内容相反,我将不得不创建自己的布局,例如 FlowLayout
这个问题有什么简单的解决办法吗?
最佳答案
您可以使用 GridView
而不是 LinearLayout
。
<GridView
android:id="@+id/tagsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"/>
这应该会自动将 TextView
放到下一行。如果你想要更有活力的东西,那么你可以使用 FlowLayout图书馆或 StaggeredLayout .看看这个SO它声称它可以替代 FlowLayout。
关于android - 一种包装 LinearLayout 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50774746/