Android 与文本内容一样宽的聊天信息框

Android 与文本内容一样宽的聊天信息框,android,android-layout,recyclerview-layout,Android,Android Layout,Recyclerview Layout,所以我想让聊天信息容器和信息一样宽。 我想实现与这种聊天信息非常相似的功能: 这是我的布局,我正在努力: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation

所以我想让聊天信息容器和信息一样宽。 我想实现与这种聊天信息非常相似的功能:

这是我的布局,我正在努力:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/single_message_view"
android:layout_margin="5dp">

<LinearLayout
    android:layout_marginEnd="15dp"
    android:layout_marginStart="15dp"
    android:layout_alignParentEnd="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="100dp"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="author"
            android:id="@+id/sender_data"
            android:layout_marginEnd="5dp"
            android:textColor="@color/colorWhite" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:textAlignment="textEnd"
            android:layout_height="wrap_content"
            android:text="date"
            android:textColor="@color/colorWhite"
            android:id="@+id/send_date" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/message_content"
        android:background="@drawable/msg_haze"
        >

        <TextView
            android:layout_margin="10dp"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/colorWhite"
            android:id="@+id/message_text"
            android:text="content" />

        <LinearLayout
            android:layout_margin="10dp"
            android:minWidth="100dp"
            android:layout_below="@id/message_text"
            android:id="@+id/tags_container"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <android.support.v7.widget.RecyclerView
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:id="@+id/message_tags"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layoutManager="LinearLayoutManager"
                tools:listitem="@layout/item_tag" />
        </LinearLayout>

        <ImageView
            android:layout_marginBottom="10dp"
            android:layout_marginEnd="10dp"
            android:paddingBottom="10dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:layout_width="15dp"
            android:layout_height="15dp"
            android:id="@+id/message_state" />

        <LinearLayout
            android:id="@+id/attachment_holder"
            android:layout_marginTop="10dp"
            android:padding="5dp"
            android:visibility="gone"
            android:orientation="vertical"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/attachments_haze">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/attachments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layoutManager="GridLayoutManager"/>

            <ImageView
                android:id="@+id/attachment"
                android:visibility="gone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

    </RelativeLayout>
</LinearLayout>


要显示聊天信息,您需要使用9个补丁图像来创建自动调整大小以适应视图内容的位图图像

要显示聊天信息,您需要使用9个补丁图像来创建自动调整大小以适应视图内容的位图图像

通常我们需要使用这种类型的聊天泡泡。这张九块的图片可以根据里面的内容重新调整大小

下面是发送和接收消息的九个补丁映像


将此图像另存为
.9.png
扩展名。使用此图像提供背景。

通常我们需要使用这种类型的聊天泡泡。这张九块的图片可以根据里面的内容重新调整大小

下面是发送和接收消息的九个补丁映像


将此图像另存为
.9.png
扩展名。使用此图像作为背景。

同意@basavannova。。9面片图像自动拉伸。。您必须提供其内容区域和拉伸区域。有很多在线工具可以创建9补丁映像。我认为即使是android studio也可以编辑9补丁文件

同意@basavannova。。9面片图像自动拉伸。。您必须提供其内容区域和拉伸区域。有很多在线工具可以创建9补丁映像。我认为即使是android studio也可以编辑9补丁文件

temp_black.xml(这将用作聊天框的背景,您可以将下面文件中的颜色更改为#FFFFFF以获得所需的输出)


temp_white.xml(这是发送者名称和时间之间的黑点,我知道图像中的颜色是黑色的,但出于参考目的,我做了这个,您不能只编辑下面xml中的颜色以获得您选择的输出)


temp.xml(布局文件)


最后输出图像 temp_black.xml(这将用作聊天框的背景,您可以将下面文件中的颜色更改为#FFFFFF以获得所需的输出)


temp_white.xml(这是发送者名称和时间之间的黑点,我知道图像中的颜色是黑色的,但出于参考目的,我做了这个,您不能只编辑下面xml中的颜色以获得您选择的输出)


temp.xml(布局文件)


最后输出图像

我认为,对于这个特定的问题,这是不必要的,因为如果您可以打开问题中的图像参考,则有一个简单的方形盒外壳,带有平面颜色,可以使用绘图工具本身获得。不需要9补丁图像。只需使用可绘制为背景的颜色逻辑地设置布局。在一段时间内发布整个布局。是的,这也是可能的。但这只是参考。大多数(并非所有)聊天泡泡都是由9个补丁组成的。是的,你完全正确,也就是说,我提到“这个问题不需要这个”@Mit我不知道你的确切意思。你能提供代码实现吗?是的,伙计,我一会儿就发布同样的内容了,我只是告诉你,这是绝对正确的,大多数聊天泡泡都需要9个补丁图片,但对于这个特定的问题,它是没有必要的,这就是我想告诉你的,对于这个特殊的问题,这是不必要的,因为如果您可以打开问题中的图像参考,则有一个简单的方形盒外壳,带有平面颜色,可以使用绘图工具本身获得。不需要9补丁图像。只需使用可绘制为背景的颜色逻辑地设置布局。在一段时间内发布整个布局。是的,这也是可能的。但这只是参考。大多数(并非所有)聊天泡泡都是由9个补丁组成的。是的,你完全正确,也就是说,我提到“这个问题不需要这个”@Mit我不知道你的确切意思。你能提供代码实现吗?是的,伙计,我一会儿就发布了同样的内容,我只是告诉你,这是绝对正确的,大多数聊天泡泡都需要9个补丁图片,但对于这个特殊的问题,它是没有必要的,这就是我想告诉你的只是将布局重心更改为右|中|垂直,以便在另一侧显示聊天框,如果需要,一定要让我知道,我可以为您提供两侧,包括只需将布局重心更改为右|中|垂直,以便在另一侧显示聊天框,如果需要,一定要让我知道,我可以为您提供包括两个方面的服务
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#000000"/>

    <padding
        android:bottom="0dip"
        android:left="0dip"
        android:right="0dip"
        android:top="0dip" />

</shape>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFFFFF"/>

    <corners android:radius="100dip" />

    <padding
        android:bottom="0dip"
        android:left="0dip"
        android:right="0dip"
        android:top="0dip" />

</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        android:layout_margin="10dp"
        android:background="@drawable/temp_black"
        android:paddingRight="10dp"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:adjustViewBounds="true"
            android:src="@mipmap/ic_launcher"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:text="Sample Text Sample Text"
                android:textSize="16sp"
                android:textColor="#FFFFFF"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_marginTop="5dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:text="Name"
                    android:textSize="11sp"
                    android:textColor="#FFFFFF"/>

                <ImageView
                    android:layout_width="5dp"
                    android:layout_height="5dp"
                    android:layout_gravity="center"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:adjustViewBounds="true"
                    android:src="@drawable/temp_white"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:text="Time"
                    android:textSize="11sp"
                    android:textColor="#FFFFFF"/>

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>