Android 根据内容调整9面片图像的大小

Android 根据内容调整9面片图像的大小,android,nine-patch,Android,Nine Patch,我需要我的9补丁图片来包装内容。如果有一个小文本,它应该是真正的小包装文本。如果有一个插入文本的图像,它也应该将其包装起来。 以下是我的9-patch png: 但在这里,它显示了内容的外观: 这是xml文件中的代码: <RelativeLayout android:id="@+id/message_text_layout" android:layout_width="wrap_content" android:layout_height="wrap_conte

我需要我的9补丁图片来包装内容。如果有一个小文本,它应该是真正的小包装文本。如果有一个插入文本的图像,它也应该将其包装起来。 以下是我的9-patch png:

但在这里,它显示了内容的外观:

这是xml文件中的代码:

<RelativeLayout
    android:id="@+id/message_text_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/other_user_layout"
    android:layout_toLeftOf="@+id/user_layout"
    android:layout_below="@id/message_date"
    >
    <TextView
        android:id="@+id/message_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:layout_marginTop="@dimen/margin"
        />
    <ImageView
        android:id="@+id/message_picture"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:scaleType="fitCenter"/>
</RelativeLayout>

我正在以编程方式设置此相对布局的背景。
如何使此消息布局与内容完全匹配,而不在屏幕上四处延伸。

问题在于:

android:layout_toRightOf="@id/other_user_layout"
android:layout_toLeftOf="@+id/user_layout"

根据消息作者的不同,我正在以编程方式设置其中一个选项。

尝试仅使用textview

<TextView
    android:id="@+id/message_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
    android:layout_marginTop="@dimen/margin"
    android:layout_background="@drawable/img"/>

而不是

<RelativeLayout
android:id="@+id/message_text_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/other_user_layout"
android:layout_toLeftOf="@+id/user_layout"
android:layout_below="@id/message_date"
>
<TextView
    android:id="@+id/message_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
    android:layout_marginTop="@dimen/margin"
    />
<ImageView
    android:id="@+id/message_picture"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:layout_centerInParent="true"
    android:scaleType="fitCenter"/>


你知道吗?您可以保存在RealtiveLayout和ImageView上,并拥有一个文本视图。所以,要想提高表演水平,我该怎么做呢?我听说我可以将图像放在textview的侧面,但我不知道如何在这里实现它。在xml中:使用
drawableRight=“@drawable/balloon”
。在Java中,使用setcompoundrwableswithintrinsicbounds()。您可以一次设置4个抽绳。那么RelativeLayout容器就没用了。