2
我遇到了TableLayout問題。它由兩列和多行組成。當第二列的TextView包含更長寬度的文本時,它會將該列中的TextView(在下面的行中)推離屏幕(向右)。相反,我希望它將文本保留在左側,並使用省略號來限制文本的末尾。任何人都可以看到我的XML有什麼問題嗎?有關TableLayout和省略號的Android問題
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#4096cc" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/roundedshape"
android:layout_margin="5dp"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Server Name"
android:textStyle="bold"
android:padding="10dip" />
<TextView
android:id="@+id/txtServerName"
android:text=""
android:gravity="right"
android:ellipsize="end"
android:padding="10dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:layout_column="1"
android:text="Status"
android:textStyle="bold"
android:padding="10dip" />
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="10dip"
android:src="@drawable/icon" />
</TableRow>
.
.
.
</TableLayout>
</LinearLayout>
感謝您的幫助,我不知道shrinkColumns。然而,我嘗試過,由於某種原因,它使得該行的高度很高,並且整個屏幕的寬度也是第二列......我根本看不到第一列。第二列中的文本也沒有用省略號進行限制。有任何想法嗎? – littleK 2011-06-17 04:03:23
2是您的佈局的正確值。您要縮小的那些TextViews列位於第二索引(第三)列中。您通過將layout_column設置爲1來開始第二列。這也是一個零索引屬性。 – 2011-06-17 04:14:35
好吧,我做了一個小小的調整,並使用了android:stretchColumns =「1」 和android:shrinkColumns =「2」,並且一切看起來不錯。感謝您的幫助! – littleK 2011-06-17 04:16:47