我試圖在我的佈局中創建一個簡單的組件,其中有兩個水平相鄰的TextViews。右邊的那個應該從左邊的一個完成。我的代碼如下:TextView中被截斷的文本寬度設置爲wrap_content
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@android:color/white"
android:textIsSelectable="false"
android:textSize="25sp" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="@android:color/white"
android:textSize="20sp" />
</LinearLayout>
我以編程方式在視圖渲染後在每個TextView上設置文本。但是,有時文本在第一個TextView中無法正確顯示 - 我可以看到寬度已正確設置,因爲第二個TextView不在其旁邊,但文本被截斷而不是使用空格。如果我鎖定/解鎖設備以刷新屏幕,則文本顯示正確(不改變TextView的寬度)。
我試着改變這個使用RelativeLayout,但我看到相同的問題。
任何想法?