布局在Android的聊天应用程序应用程序、布局、Android

2023-09-04 07:34:20 作者:扰川

我正在为Android聊天,我需要做一个主要的XML布局。 这里将是一个TextView显示历史的EditText和发送键。所有视图的位置应像WhatsApp的。的EditText和按钮在屏幕的底部。该空间的其余部分进到TextView的。 所以,怎么可能做到这一点,所以才好看在任何屏幕,任何方位? 我试图与Android做到这一点:layout_weight,但我不认为这将是非常便携。 先谢谢了。

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.

推荐答案

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

I don't think a single TextView is the best way to achieve this.

我推荐使用的一个的ListView 代替巨人的TextView保持整个会话历史记录。在ListView的每个元素都将拥有一个单独的TextView和任何其他所需的意见,以在历史显示一个信息,它会默认允许上下滚动查看整个历史。然后,你可以调整文字的大小,以处理不同尺寸的屏幕。

I'd recommend using a ListView instead of a giant TextView to hold the entire conversation history. Each element in the ListView would hold a single TextView and any other required views to display each message in the history, and it will by default allow for scrolling up and down to view the entire history. You can then just adjust the text size to handle different screen sizes.

这是默认的Andr​​oid消息应用程序是如何实现的,但你可以在ListView中自定义每一个项目,使它看起来你怎么想(像WhatsApp的,例如)。

This is how the default Android Messaging app is implemented, but you can customize each item in the ListView to make it look how you want (like WhatsApp, for example).

希望这有助于。