我有一個相當簡單的佈局麻煩斑點。那就是:佈局麻煩
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/id1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/id2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
3個問題:
如何中心垂直兩個TextViews(也許還好說,這些觀點中的文本)母公司的LinearLayout內?左視圖垂直居中確定,但正確的(因爲它具有較小的字體)不是。它似乎在頂部垂直居中。我顯然嘗試玩第二種視圖的layout_gravity,但這沒有任何區別。我能解決這個問題的唯一方法是將第二個TextView放在一個LinearLayout中,並將其佈局高度參數設置爲match_parent(但這是否是正確的方式?)
同樣,我希望左側的視圖水平居中在左側,右側的視圖水平居中在右側。目前右側視圖立即放置在左側旁邊。我可以解決這個問題的唯一方法是將這樣的插圖中的兩個文本觀點:
<TextView android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:text="">
基本上作爲它的大小取決於文本的legth兩個TextViews減少間隔
如果視圖的組合文本不能水平放置,我希望左側視圖中的文本被截斷。沒有包裝到新的生產線上。目前,左側視圖中的文字只是將「正確」的文字從父文件中「推出」。不知道如何實現這一點(除了添加
android:maxLines="1"
來阻止文本換行)。我試過android:ellipsize="end"
但這似乎沒有任何影響。
在線性佈局中設置android:gravity =「center_vertical」。 –
謝謝。這回答了第一部分! – Lieuwe