Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.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
Android Eclipse线性布局,多个文本视图不换行_Android_Eclipse_Textview_Android Linearlayout - Fatal编程技术网

Android Eclipse线性布局,多个文本视图不换行

Android Eclipse线性布局,多个文本视图不换行,android,eclipse,textview,android-linearlayout,Android,Eclipse,Textview,Android Linearlayout,我有一个带有多个文本视图的水平线性布局。布局的宽度为fill\u parent,高度为wrap\u内容。我的问题是,当文本视图超过设备允许的屏幕宽度时,它会将最后一个文本视图向右粉碎,而不是将其换行(这是我想要的结果)。我认为有一个高度的包装内容可以解决这个问题 如果文本视图超过父视图的宽度,如何使具有多个文本视图的线性布局包裹文本视图 以下是我的布局中的一个片段: <LinearLayout android:id="@+id

我有一个带有多个文本视图的水平线性布局。布局的宽度为fill\u parent,高度为wrap\u内容。我的问题是,当文本视图超过设备允许的屏幕宽度时,它会将最后一个文本视图向右粉碎,而不是将其换行(这是我想要的结果)。我认为有一个高度的包装内容可以解决这个问题

如果文本视图超过父视图的宽度,如何使具有多个文本视图的线性布局包裹文本视图

以下是我的布局中的一个片段:

<LinearLayout
                                android:id="@+id/linearLayout20"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:paddingTop="3dip" >

                                <TextView android:layout_height="wrap_content" android:textColor="@color/black" android:text="Car Info:  " android:id="@+id/textView023" android:layout_width="wrap_content" android:textStyle="bold" android:textSize="@dimen/item_main_text_size"></TextView>
                                <TextView android:layout_height="wrap_content" android:textColor="@color/black" android:text="2005" android:id="@+id/autorental_item_caryear" android:layout_width="wrap_content" android:textSize="@dimen/item_main_text_size"></TextView>
                                <TextView android:layout_height="wrap_content" android:textColor="@color/black" android:paddingLeft="3dip" android:text="Chevy" android:id="@+id/autorental_item_carmake" android:layout_width="wrap_content" android:textSize="@dimen/item_main_text_size"></TextView>
                                <TextView android:layout_height="wrap_content" android:textColor="@color/black" android:paddingLeft="3dip" android:text="Rio" android:id="@+id/autorental_item_carmodel" android:layout_width="wrap_content" android:textSize="@dimen/item_main_text_size"></TextView>
                                <TextView android:layout_height="wrap_content" android:textColor="@color/black" android:paddingLeft="3dip" android:text="-" android:id="@+id/textView2" android:paddingRight="3dip" android:layout_width="wrap_content" android:textSize="@dimen/item_main_text_size"></TextView>
                                <TextView android:layout_height="wrap_content" android:textColor="@color/black" android:paddingLeft="3dip" android:text="Red" android:id="@+id/autorental_item_carcolor" android:layout_width="wrap_content" android:textSize="@dimen/item_main_text_size"></TextView>
                            </LinearLayout>
我希望它是这样的:

Car Info:  2002 Chevrolet Silverado - Pu
                                     rp
                                     le 
Car Info:  2002 Chevrolet Silverado - 
Purple

如果线性布局包含多个文本视图(或按钮等其他内容),则无法获得所需的结果:

每个水平/垂直线性布局都为其子视图提供了水平/垂直边界,在该边界中,每个子视图都可以做自己的事情。因此,每个视图只能在没有边界的方向上展开,在您的案例中是垂直的

这里有一个例子说明了这个问题。外部虚线表示屏幕边框

| First Text- | Short text | Long text will take all the space possible | T |
| View with   |            |                                            | e |
| additional  |            |                                            | x |
| given       |            |                                            | t |
| maximum     |            |                                            |   |
| width. Long |            |                                            |   |
| text makes  |            |                                            |   |
| it expand   |            |                                            |   | 
| down        |            |                                            |   |

您可以通过将所有文本放入单个textview来解决此问题。然后,如果您想创建一个好的列表,您还需要格式化您放入其中的字符串。

使用
线性布局无法实现该结果。我认为在这种情况下,最好的解决方案是使用一个带有多个样式的
TextView
(如果您需要文本的动态值)。请查看此处以获取见解:


如果您使用的是静态文本,则可以在strings.xml中的CDATA块中包含一个兼容html的值,并直接在布局中使用它。

您希望TextView具有相同大小的宽度吗?不,它们不需要大小相同。它们将根据稍后输入的内容而有所不同。我只想这样,如果文本视图中的文本变得太长,以至于无法放在一行上,它将换行到下一行。现在,如果文本太长,它会将最后一个文本视图向右粉碎,使其有多行长,但每行只有1-2个字符,都会向右粉碎,这是有意义的。谢谢你简洁明了的回答