我有两个TextView以水平LinearLayout
排列。因为它们只显示几个单词,所以第一个单词仅限maxLines=1
和ellipsize=marquee
。
通常,它看起来像这样:
TextView1中的文字 TextView 2中的文字
但是,如果TextView 1太长,TextView 2将不再可见,因为第一个占用了所有空间:
TextView1中的文字文字文字文字......
现在,我只想对TextView 1进行椭圆化处理,以便TextView2始终完全可见。我已经尝试将layout_weight="1"
设置为第一个,但是在没有省略时会留下空间。
TextView1中的文字 ------------------- TextView 2中的文字
答案 0 :(得分:7)
是否必须是LinearLayout
?
如果不是:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
tools:context=".MainActivity">
<TextView
android:id="@+id/textview1"
android:text="This is a very very long string that eventually will get out of screen; yes, it is that long!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/textview2"
android:layout_toStartOf="@id/textview2"/>
<TextView
android:id="@+id/textview2"
android:text="Hello! I'm short!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>