【发布时间】:2011-10-04 00:58:30
【问题描述】:
我想创建一个类似消息的 UI。我正在创建一个包含两种类型行的列表视图:左行和右行。
每一行包含一个TextView。左侧用于显示来自发件人的消息,而右侧用于显示来自当前用户的消息。
我想要做的是将右侧的 TextView 设置为占据屏幕的一定百分比,使文本向左对齐,但随着内容动态增长。
为了澄清,这是我想要实现的图像:http://dl.dropbox.com/u/2482095/wanted.png
蓝色行是“左”行,黑色行是“右”行。
为了实现这一点,我使用了 LinearLayout 和 RelativeLayout 的各种组合,左侧放置了一个空视图,右侧放置了所需的 textView。我得到的是这样的东西,这不是我想要的:http://dl.dropbox.com/u/2482095/notWanted1.png(文本总是从确切的点开始)
我还设法设置了重力:右,它将文本向右对齐,这也不是我想要的。
有什么方法可以让 TextView 随内容一起增长?
[编辑] 我的 xml 文件看起来像这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<View android:id="@+id/emptyView"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:id="@+id/messageBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
【问题讨论】: