2015-06-25 44 views
0

我需要一个双列布局,其中右列是一个固定字符串,左列可以是任意长度的文本,并且如果它不合适,应该包装。如何在两列布局中固定固定长度和可变长度的TextViews?

换句话说,我想这一点:

+-----------------------------------------------------------+------------+ 
| This text may be any length and should wrap if it doesn't | Fixed Text | 
| fit in the first column.         |   | 
+-----------------------------------------------------------+------------+ 

而是我总是得到这样的:

+------------------------------------------------------------------------+ 
| This text may be any length and should wrap if it doesn't fit in the | 
| first column.               | 
+------------------------------------------------------------------------+ 

我试过的RelativeLayout,并与宽度和重量的各种组合一的LinearLayout,但我通常会得到第二个结果。

而不是张贴我所有失败的尝试,有人可以只发布什么工作?这不应该是这么难。 > 8-(

在此先感谢...

回答

1

试试吧

<LinearLayout 
android:layout_width=“match_parent” 
android:layout_height="wrap_content" 
android:weightSum="1" 
android:orientation="horizontal" 
> 
    <TextView 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 

    /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    /> 
</LinearLayout> 
+0

这一个工作。谢谢! –

0

尝试使用的LinearLayout与sepecific重量

<LinearLayout 
<!-- This will hold a row --> 
android:weightSum="3" 
android:orientation="horizontal" 
...> 
    <LinearLayout 
    <!-- Variable TextView placeholder--> 
    android:weight="1" 
    android:layout_width="fill_parent" 
    ...> 
    <!-- TextView here --> 
    </LinearLayout> 
    <LinearLayout 
    <!-- Fixed TextView placeholder--> 
    android:weight="2" 
    android:layout_width="fill_parent" 
    ...> 
    <!-- TextView here --> 
    </LinearLayout> 
</LinearLayout> 
0

尝试表布局:

<?xml version="1.0" encoding="utf-8"?> 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/tableLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="5dip" > 

    <TextView 
     android:id="@+id/textView1" 
     android:text="Column 1" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_weight=".67"/> 

    <TextView 
     android:id="@+id/textview2" 
     android:text="Column 2" 
     android:layout_weight=".33"/> 
</TableRow> 

</TableLayout>