android - 一种包装 LinearLayout 的方法

标签 android xamarin

几周来我一直在尝试为此寻找解决方案,并一直将其放在我的待办事项列表中,但我无法包装 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);

结果如下 enter image description here

看到最后一个 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/

相关文章:

java - Vogella Android 教程,Android Studio 中的编译器错误

android - 将字符串从 FragmentActivity 传递到 Fragment

android - 使用 setContent 时自定义通知崩溃

android - MvvmCross绑定(bind)+Android EventHandler

c# - 加载 JSON 数据失败

ios - 在这个非常基本的 UIScrollView 中我做错了什么

c# - 自定义标签中的 Xamarin 可点击子字符串

java - onTouch() 未触发

.net - 滚动ListView时出现错误 "Cannot access a disposed object"

android - CharlesProxy -Cisco Anyconnect - Android