2011-08-10 63 views
2

在我的android應用程序中,我想在同一行中實現2個文本字段。如果文字很長,可以轉到下一行。所以我使用了橫向更精細的佈局並添加了2個文本字段。Android同行文本視圖

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1"> 
<TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
<TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView></LinearLayout> 

[例如:TextView1,TextView2]

問題是,當TextView1的文字是有點長但仍嘗試打印於一身行,陷入困境。

我想要的結果是,

如果

TextView1 = aaaaaaaaaaaaaaaaaaaa & TextView2 = bbbbbbbbbbbbbbbbb

aaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbb 
bbbbbb 

沒有任何人有一個如何做到這一點的想法。謝謝。

回答

0

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="This is the textview1 in the linearlayout" 
    android:layout_weight="1" 
    android:background="#0a30aa" 
    /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="this is textview2 in the linearlayout" 
    android:layout_weight="1" 
    android:background="#990099" 
    /> 
</LinearLayout> 
0

只是

android:layout_weight="1" 

屬性添加到您的textviews,這將是做這項工作。

+0

我想要在一行中打印textView1內容,並且如果對於textview 2不夠,請轉到下一行。 (例如,如果textView1是aaaaaaaaaaaaa並且textview2是bbbbbbbbbbb,則在一行中輸入aaaaaaaaaa,然後如果空格不足以在同一行中鍵入bbbbbbbbb類型,並且bbbbbbb的一半類型會轉到下一行)。當我添加android:layout_weight =「1」時,在一行中輸入textview1的一半,然後在TextView2中輸入另一半的下一行和相同的東西 – JibW