简体   繁体   English

Textview行不能正确换行

[英]Textview lines not wrapping correctly

I have a ListView which I've created a custom view for each row. 我有一个ListView,我为每行创建了一个自定义视图。 My view consist of two text view that I want to display side by side. 我的视图包含两个要并排显示的文本视图。 The first textview (idno) has a background image set which I center my text over. 第一个textview(idno)有一个背景图像集,我将其文本居中放置。 The second textview (materials) has a variable number of lines for each row. 第二个textview(材料)每行的行数是可变的。

The issue that I'm having is that the lines go beyond the right side before wrapping. 我遇到的问题是,在包装之前,线条超出了右侧。 It seems that it is not accounting for the first textview width. 似乎没有考虑到第一个textview宽度。

Here is my layout file: 这是我的布局文件:

<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<TableRow>
    <TextView 
        android:id="@+id/idno"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:gravity="center"
        android:textColor="#000000"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>    
    <TextView 
        android:id="@+id/materials"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:textColor="#0000ff"
        android:textStyle="bold"
        android:textSize="12sp"
        android:maxLines="5"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</TableRow> 

Any suggestions or solutions would be very much appreciated. 任何建议或解决方案将不胜感激。 Thanks in advanced! 提前致谢!

I would suggest you to use LinearLayout with orientation="horizontal" to display two TextViews like : 我建议您将LinearLayoutorientation="horizontal"一起使用,以显示两个TextView,例如:

<LinearLayout
    android:orientation="horizontal">
    <TextView/>
    <TextView/>
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM