【问题标题】:Create a Chat Bubble In Android在 Android 中创建聊天气泡
【发布时间】:2012-02-22 17:12:13
【问题描述】:

我正在尝试用一些文本创建一个聊天气泡。为此,我创建了三个布局,在主线性布局内部我正在使用 FramLayout,我正在为这个 Framlayout 设置一个 9-patch 背景。我在 Framlayout 内部在我放置三个 textView 和一个 imageView 的位置再添加一个 RelativeLayout。但是键入长文本,它超出了 FramLayout 边框。我不知道我做错了什么或我错过了什么。当我使用小文本时,它仍然存在适合,但带有大文本,它甚至会从 FramLayout 的背景边框出来。在附件中,我正在展示我的气泡和雅虎 IM 气泡。我正在尝试创建与雅虎相同但风格不同的内容。请给我你的建议。我试试有很多不同的方法,但没有成功。在此先感谢。 . 我在这里放置我的布局文件

     <?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>

【问题讨论】:

  • 我们需要查看布局文件。对于这类事情,我偏爱线性/相对布局。 FrameLayouts 可能会有点毛茸茸的 IMO。
  • 你试过弄乱填充吗?
  • 是的,我也尝试使用填充并使用边距。
  • 我写了一篇关于android chat bubbles的博文,你也可以在那里找到开源代码。

标签: android android-layout android-widget


【解决方案1】:

在创建 .9patch 图像时,您还必须指定一个内容区域,该区域由左侧和底部像素定义。 Check out this.

【讨论】:

【解决方案2】:

使用

用于您的根布局项目的背景。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多