这是我在这里的第一个问题,因为我发现自己被(又一个)应该简单但不是布局问题难住了。我试图横向布局两个textview,说标题和作者,这样:
标题左对齐作者右对齐作者包装内容,必要时展开,从不截断。Title将填充剩余的空格,并在必要时填充末尾的省略号。
所以我们有这样的东西:A.作者|这是一个很长的…求职博客||又一个标题……A.较长的名称|
我想不出任何设置组合来实现这个。我知道问题是布局是从左到右执行的,所以Title不知道它有多少空间,因为Author还没有被渲染。但与此同时,如此明显的布局必须是可实现的?
感谢您的帮助。
你不应该用RelativeLayout来解决这个问题吗?像这样:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/title_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/author_textview"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:id="@+id/author_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
这很简单。最有趣的部分是,你有右对齐的作者textview换行它的宽度,左对齐的标题textview填充它,但添加一个约束,后者应该留在前者的左边。