在Android中创建聊天气泡

9

我正在尝试创建一个聊天气泡,其中包含一些文本。为此,我创建了三个布局,在主线性布局内部使用FramLayout,将一个9-patch背景设置为该Framlayout。在Framlayout内部,我添加了另一个RelativeLayout,其中放置了我的三个TextView和一个ImageView,但是当类型为长文本时,它会超出FramLayout边框。我不知道我做错了什么或者我漏掉了什么。当我使用小文本时,它仍适合,但是使用大文本时,它甚至从FramLayout的背景边框中出现。在附件中,我展示了我的气泡和Yahoo IM气泡。我正在尝试创建与Yahoo相同但具有不同风格的气泡,请给我建议。我用不同的方法尝试了很多次,但没有成功。谢谢。

enter image description here
     <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/linearListLayout1">

       <FrameLayout
           android:id="@+id/frameLayout1"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:background="@drawable/bubbleblue" >

            <RelativeLayout
              android:id="@+id/relativeLayout1"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" 
              android:minHeight="100dp">

                <TextView
                    android:id="@+id/chattitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextView"
                    android:layout_marginTop="10dp"
                    android:layout_marginLeft="10dp"/>

               <TextView android:id="@+id/chatdate"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="TextView"
                    android:layout_alignParentRight="true"
                    android:layout_marginTop="10dp"/>

               <TextView android:id="@+id/chatText"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_alignBottom="@+id/chatstatus"
                   android:layout_below="@+id/chattitle"
                   android:layout_toLeftOf="@+id/chatstatus"
                   android:text="TextView" />

              <ImageView
                  android:id="@+id/chatstatus"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:src="@drawable/add_picture"
                  android:layout_alignParentRight="true"
                  android:layout_below="@+id/chatdate"
                  android:minHeight="2dip"
                  android:maxWidth="2sp"
                  android:maxHeight="2sp"
                  android:layout_marginRight="2dp"/>
        </RelativeLayout>
  </FrameLayout>


我们需要查看布局文件。我个人偏向于使用线性/相对布局来处理这种情况。在我看来,帧布局可能会变得有点混乱。 - Phix
你尝试过调整填充(padding)吗? - jmcdale
是的,我也会尝试使用padding和margin。 - aftab
我写了一篇关于Android聊天气泡的博客文章,您也可以在那里找到开源代码。 - Adil Soomro
2
请查看此项目:https://github.com/madhur/android-chat-starter - Madhur Ahuja
2个回答

4
创建.9patch图像时,您还必须指定内容区域,可以使用左侧和底部像素定义该区域。请参考此链接

嗨,对于9-patch,我做的事情与您链接中提供的相同。http://developer.android.com/guide/developing/tools/draw9patch.html - aftab
@user717572 页面未找到。 - Wijay Sharma

0

使用 输入图像描述输入图像描述

作为根布局项的背景。

右键单击图像,选择 目标另存为


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接