在xml中聊天布局

时间:2012-04-09 18:03:43

标签: java android xml chat

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

如何将这些气泡图像作为此chat.xml中聊天文本的背景,如何添加ListView是否重要?

chatting.xml

Chatting

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

1 个答案:

答案 0 :(得分:1)

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

相关问题