如何在我的应用程序中创建这种类型的聊天布局?

时间:2022-02-26 07:34:18

I am developing one chat application and i want to create a chat screen layout like following screen.如何在我的应用程序中创建这种类型的聊天布局?

我正在开发一个聊天应用程序,我想创建一个聊天屏幕布局,如下面的屏幕。

Currently i am using ListView for my chat texts but the problem is that to read the long chats i have to scroll down,my screen does not scrolls automatically.

目前我正在使用ListView作为我的聊天文本,但问题是要阅读我必须向下滚动的长聊天,我的屏幕不会自动滚动。

I want this bubble kind of chat layout.
How do i develop this kind of chat layout.
If you have any idea about this please share with me.

我想要这种泡泡式的聊天布局。我如何开发这种聊天布局。如果您对此有任何疑问,请与我分享。

thanks

4 个解决方案

#1


7  

What you need here is a layout with a header and footer part, having as a main view a ListView.

你需要的是一个带有页眉和页脚部分的布局,作为主视图的ListView。

This ListView should have a custom Adapter to show the message items.

此ListView应具有自定义适配器以显示消息项。

To achieve this bubble-like display, your itemRenderer should be able to deal with states (fromMe - fromOther).

要实现这种类似气泡的显示,您的itemRenderer应该能够处理状态(fromMe - fromOther)。

To have the bubbles, you should attach different backgroundDrawable (bubble 9patches pointing to the left and right) to different states.

要获得气泡,您应该将不同的backgroundDrawable(指向左侧和右侧的气泡9个样本)附加到不同的状态。

If you have stuck somewhere, share the relevant code snippets and logcat output, so we can help you further.

如果您已经卡在某处,请共享相关的代码片段和logcat输出,以便我们为您提供进一步的帮助。

#2


2  

try looking at this for creating a custom view for listView.

尝试查看这个为listView创建自定义视图。

I would create a parent View and an incoming one and outgoing one that inherit from it and change color and gravity according to the one they are.

我将创建一个父视图和一个传入的视图和一个从它继承的传出视图,并根据它们改变颜色和重力。

#3


2  


U need the Following
1) A ListActivity, ListView XML Layout.
2) BaseAdapter which ListActivity Uses.
3) BaseAdapter getView will inflate each Row.
4) In Each Row have a row View with you bubble images and your chat text.
5) In Listview Footer have a EditText View to Type Chat.

你需要以下1)ListActivity,ListView XML布局。 2)ListActivity使用的BaseAdapter。 3)BaseAdapter getView将为每一行充气。 4)在每一行中都有一行视图,其中包含气泡图像和聊天文本。 5)在Listview中,页脚有一个EditText视图来键入聊天。

Use these for reference.. http://developer.android.com/reference/android/app/ListActivity.html

使用这些参考.. http://developer.android.com/reference/android/app/ListActivity.html

http://developer.android.com/reference/android/widget/BaseAdapter.html

#4


1  

OK if I understand you correctly all you need to do is implement auto-scroll for the Listview.

好的,如果我理解正确你需要做的就是为Listview实现自动滚动。

if so then try calling smoothScrollToPosition each time something is added. I don't know what your class looks like but maybe can run something like this (pseudo code)

如果是这样,那么每次添加内容时都尝试调用smoothScrollToPosition。我不知道你的班级是什么样的,但也许可以运行这样的东西(伪代码)

customListview.addNewChat(...);
customListView.smoothScrollToPosition(customListView.getCount());

#1


7  

What you need here is a layout with a header and footer part, having as a main view a ListView.

你需要的是一个带有页眉和页脚部分的布局,作为主视图的ListView。

This ListView should have a custom Adapter to show the message items.

此ListView应具有自定义适配器以显示消息项。

To achieve this bubble-like display, your itemRenderer should be able to deal with states (fromMe - fromOther).

要实现这种类似气泡的显示,您的itemRenderer应该能够处理状态(fromMe - fromOther)。

To have the bubbles, you should attach different backgroundDrawable (bubble 9patches pointing to the left and right) to different states.

要获得气泡,您应该将不同的backgroundDrawable(指向左侧和右侧的气泡9个样本)附加到不同的状态。

If you have stuck somewhere, share the relevant code snippets and logcat output, so we can help you further.

如果您已经卡在某处,请共享相关的代码片段和logcat输出,以便我们为您提供进一步的帮助。

#2


2  

try looking at this for creating a custom view for listView.

尝试查看这个为listView创建自定义视图。

I would create a parent View and an incoming one and outgoing one that inherit from it and change color and gravity according to the one they are.

我将创建一个父视图和一个传入的视图和一个从它继承的传出视图,并根据它们改变颜色和重力。

#3


2  


U need the Following
1) A ListActivity, ListView XML Layout.
2) BaseAdapter which ListActivity Uses.
3) BaseAdapter getView will inflate each Row.
4) In Each Row have a row View with you bubble images and your chat text.
5) In Listview Footer have a EditText View to Type Chat.

你需要以下1)ListActivity,ListView XML布局。 2)ListActivity使用的BaseAdapter。 3)BaseAdapter getView将为每一行充气。 4)在每一行中都有一行视图,其中包含气泡图像和聊天文本。 5)在Listview中,页脚有一个EditText视图来键入聊天。

Use these for reference.. http://developer.android.com/reference/android/app/ListActivity.html

使用这些参考.. http://developer.android.com/reference/android/app/ListActivity.html

http://developer.android.com/reference/android/widget/BaseAdapter.html

#4


1  

OK if I understand you correctly all you need to do is implement auto-scroll for the Listview.

好的,如果我理解正确你需要做的就是为Listview实现自动滚动。

if so then try calling smoothScrollToPosition each time something is added. I don't know what your class looks like but maybe can run something like this (pseudo code)

如果是这样,那么每次添加内容时都尝试调用smoothScrollToPosition。我不知道你的班级是什么样的,但也许可以运行这样的东西(伪代码)

customListview.addNewChat(...);
customListView.smoothScrollToPosition(customListView.getCount());