【发布时间】:2014-09-25 15:51:24
【问题描述】:
我正在尝试在我的布局中创建一个简单的组件,其中有两个水平相邻的 TextView。右边的应该从左边的结束的地方开始。我的代码如下:
<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 不在它旁边,但文本被截断而不是使用空间。如果我锁定/解锁设备以刷新屏幕,则文本会正确显示(TextViews 的宽度不会改变)。
我尝试将其更改为使用 RelativeLayout,但我看到了同样的问题。
有什么想法吗?
【问题讨论】:
标签: android android-layout textview