Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果布局中没有空格,则自动在下一行中查看文本_Java_Android_Android Studio 3.0 - Fatal编程技术网

Java 如果布局中没有空格,则自动在下一行中查看文本

Java 如果布局中没有空格,则自动在下一行中查看文本,java,android,android-studio-3.0,Java,Android,Android Studio 3.0,如果文本视图不适合当前行,我想自动将其移到下一行。例如,我在一个布局中有20个文本视图,并希望在其中设置客户名称。有些客户的名字很长,有些很小。根据该行的可用空间,应显示TextView。若并没有空间,它会自动移动到布局中的下一行 有人能帮我吗?标准Android框架中没有任何东西可以让你这么做,但是Google有一个非常好的外部库,名为,可以帮你这么做 您可以使用FlexboxLayout作为所有TextView的父视图,而不是LinearLayout,它将为您包装它们 <com.goo

如果文本视图不适合当前行,我想自动将其移到下一行。例如,我在一个布局中有20个文本视图,并希望在其中设置客户名称。有些客户的名字很长,有些很小。根据该行的可用空间,应显示TextView。若并没有空间,它会自动移动到布局中的下一行


有人能帮我吗?

标准Android框架中没有任何东西可以让你这么做,但是Google有一个非常好的外部库,名为,可以帮你这么做

您可以使用
FlexboxLayout
作为所有
TextView
的父视图,而不是
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”
,因为默认情况下不进行包装。我不知道这是为什么,因为使用这个库的全部目的是为了包装,但是嘿。

标准Android框架中没有任何东西可以让你这么做,但是谷歌有一个非常好的外部库,名为,可以为你做

您可以使用
FlexboxLayout
作为所有
TextView
的父视图,而不是
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”
,因为默认情况下不进行包装。我不知道这是为什么,因为使用这个库的全部目的是为了包装,但是嘿。

听起来你好像在尝试将一些文本视图芯片化。您需要某种布局管理器来测量视图并确定如何显示它们。在Github上查看此信息,或者任何与ContactChips相关的信息都可能有用

听起来你在尝试将一些文本视图芯片化。您需要某种布局管理器来测量视图并确定如何显示它们。在Github上查看此信息,或者任何与ContactChips相关的信息都可能有用

创建线性布局,使用高度作为换行内容,宽度作为匹配父级,而不是内部,在内部创建Textview,并将其高度作为换行内容,这样当内容增加时,它将自动展开。就这么简单。你可以查看下面的例子

 <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> 

创建线性布局,使用高度作为换行内容,使用宽度作为匹配父项,然后在内部创建文本视图,并将其高度作为换行内容,以便在内容增加时自动展开。就这么简单。你可以查看下面的例子

 <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> 


亲爱的Ben P,根据您的建议,我使用了此代码并添加了5个文本视图,但在版面中没有显示任何内容。您应该检查我的完整答案亲爱的Ben P,根据您的建议,我使用了此代码并添加了5个文本视图,但在版面中没有显示任何内容。您应该检查我的完整答案