【问题标题】:Android chat application-xml layoutAndroid聊天应用-xml布局
【发布时间】:2012-09-21 10:47:56
【问题描述】:

我正在为 Android 制作一个聊天应用程序。聊天画面应该如何?谁能告诉我在 XML 布局中应该使用哪些视图?它是一个编辑文本和一个列表视图吗?请帮忙。我需要制作一个像我们在 Gtalk 中看到的那样的聊天屏幕。双方的聊天消息应该对齐到屏幕的相对两侧(请参阅 Gtalk 聊天框对齐样式)。这就是我想要的..我该如何实现这种布局? http://upload.wikimedia.org/wikipedia/en/7/75/Google_talk.gif

【问题讨论】:

  • @raghav sood 我可以从服务器检索用户详细信息,但我不知道如何显示对话中双方的聊天消息。我需要单个列表视图、一个编辑文本和一个提交按钮还是文本视图和编辑文本和按钮?这是我的疑问
  • 我建议你去阅读一些关于适配器的教程,尝试实施教程,然后,如果你在某些特定点上遇到问题,请回来询问。
  • @Budis 我做了所有这些事情。我仍然很困惑哪种方式更好,请提出一个
  • Creating a chat layout?的可能重复

标签: android xml layout client-server chat


【解决方案1】:

找到合适的。所以在这里分享一下

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ScrollView 
    android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:layout_weight="1"  >
    <TextView 
        android:text="@string/text" 
        android:id="@+id/textOutput"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        android:paddingTop="5dp" />
</ScrollView>

<LinearLayout 
    android:id="@+id/linearLayout1"
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp"
    android:paddingBottom="5dp"
    android:baselineAligned="true">
    <EditText android:layout_weight="1" android:id="@+id/textInput"
        android:layout_height="45dp" android:layout_width="0dip">
        <requestFocus></requestFocus>
    </EditText>
    <Button android:text="Send"
        android:layout_height="45dp" android:layout_width="125dp"
        android:id="@+id/btnSend"></Button>
</LinearLayout>

【讨论】:

    【解决方案2】:

    您应该查看一些关于回收器视图和适配器的教程。您可以创建两个查看器,一个用于发送的消息,另一个用于接收的消息,并根据消息的类型对它们进行扩展。

    此链接提供了有关如何创建聊天 UI 的示例。 https://blog.sendbird.com/android-chat-tutorial-building-a-messaging-ui

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 2018-02-17
      • 2015-11-23
      相关资源
      最近更新 更多