-3

I'm making a chat for Android and I need to make a main xml layout. There is going to be a TextView to display history, EditText and Send Button. All view should be positioned like in whatsapp. EditText and Button at the bottom of a screen. The rest of the space goes to the TextView. So how is it possible to do it, so it would look nice at any screen and any orientation? I tried to do it with android:layout_weight, but I don't think it's going to be very portable. Thanks in advance.

4

2 回答 2

2

我不认为单个 TextView 是实现这一目标的最佳方式。

我建议使用ListView而不是巨大的 TextView 来保存整个对话历史记录。ListView 中的每个元素都将包含一个 TextView 和任何其他必需的视图来显示历史记录中的每条消息,并且默认情况下允许上下滚动以查看整个历史记录。然后,您可以调整文本大小以处理不同的屏幕大小。

这是默认的 Android 消息应用程序的实现方式,但您可以自定义 ListView 中的每个项目以使其看起来像您想要的那样(例如 WhatsApp)。

希望这可以帮助。

于 2013-11-01T18:49:38.450 回答
1

因为 layout_weight 设置了比例,但是我的editText/Button的高度是固定的

所以?不要放在android:layout_weight固定部分。

所以对于不同的屏幕尺寸,会给他们不同的高度,留下一些空间。

然后不要放在android:layout_weight固定部分。你用锤子敲自己的头,然后抱怨你的头疼。

步骤#1:垂直LinearLayout

第 2 步:TextView在 中的成绩单LinearLayout,高度为 0,重量为 1。

步骤#3:EditTextButton(在水平LinearLayout?),在垂直内LinearLayout,高度为wrap_content,没有指定重量(默认为0)。

你的固定高度的东西,高度为wrap_content,将得到它的像素分配,你的成绩单TextView将得到所有剩余的像素,由于它的权重为 1。

我也赞同 physphil 的建议,即为ListView您的聊天记录使用 in transcript 模式,而不是TextView.

于 2013-11-10T14:35:35.563 回答