2012-12-12 34 views
1

我必須在一行中放置兩個文本視圖。第二個應該放在第一個旁邊(如圖1所示)。佈局兩個文本視圖

我的問題是:第一個文本視圖的文本可能很長,所以我需要橢圓化它。它應該佔用足夠的空間,以便能夠在第二個文本視圖中閱讀整個文本。圖2顯示了它。

是否有可能使用Android內置通俗語言來實現該功能,或者需要編寫自定義視圖?

screenshot

回答

0

創建內的佈局和使用android:weightSum="100"屬性。然後放置兩個文本視圖insode此內部佈局,並將屬性android:layout_weight="50"添加到每個文本視圖!

0

嘗試是這樣的

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" > 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:ellipsize="end" 
    android:text="A long long text" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="A long text" /> 

</LinearLayout> 

問候

+0

你好。它的工作幾乎和預期的一樣(我使用Relative佈局獲得了相同的結果)。當第一個文本視圖字符串很短時(例如「test」),第二個文本視圖放置在其父項的右側(此處爲線性佈局)。但在這種情況下,我希望他們兩個都與左邊對齊。 – user464592

相關問題