java - xml中的聊天布局

标签 java android xml chat

如下图+xml代码所示,我在chatting.xml中创建了这个设计,然后我用9-Patch创建了2个气泡图像,但我的问题是:

我怎样才能把这些气泡图像作为聊天文本的背景在这个chatting.xml 中,我怎样才能添加ListView 这很重要吗?

聊天.xml

Chatting

聊天.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frameLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/MidnightBlue"
    android:padding="5dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="30dip"
            android:layout_weight=".99"
            android:background="@color/LightGray" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="TextView" />
        </ScrollView>

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="true"
            android:orientation="horizontal"
            android:paddingBottom="0dp"
            android:paddingLeft="4dp"
            android:paddingRight="1dp" >

            <EditText
                android:id="@+id/textInput"
                android:layout_width="0dip"
                android:layout_height="40dp"
                android:layout_weight="1" />

            <Button
                android:id="@+id/btnSend"
                android:layout_width="80dp"
                android:layout_height="45dp"
                android:textColor="@color/MidnightBlue" 
                android:text="Send"
                />
        </LinearLayout>
    </LinearLayout>

</FrameLayout>

气泡图:

enter image description here

最佳答案

在chatting.xml 中为气泡创建一个新的 ImageView 。将它的焦点设置为 false,android:focusable="false" 您只希望在收到文本时显示气泡。 至于 ListView ,是的,您需要一个,因为您希望能够格式化对话,为每条消息说一个新行。在 chatting.xml 中创建一个 ListView 。 ListView 应自动滚动,因此您不需要 ScrollView 。

关于java - xml中的聊天布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10077553/

相关文章:

java - 使用resteasy/jax-rs从请求有效负载接收两种类型的数据

java - 我的代码 PhysicsRemoveExample.java (AndEngine) 有什么问题?

java - JAXB 编码/解码具有 List 变量成员的类对象

java - 保存图像时添加 toast Eclipse

Java:NetworkInterface.getName() 是一个不会随时间变化的唯一标识符吗?

javascript - XSLT 分页显示一些计算的节点值以及在下一行检索到的前一行值 (II)

java - 二进制/合格名称错误?以 : <any? >$ 开头

java - 如何测试调用私有(private)方法的匿名内部类

java - 为什么我这里不能有 'void' 类型?

java - 使用以 String 数组作为元素的 ArrayList 填充 ListView