9补丁图像未拉伸

时间:2019-03-08 21:17:49

标签: android kotlin nine-patch

我正在尝试使用9个补丁图像显示此气球,尽管根据我定义的文本,看起来的背景似乎并未拉伸。

我已经按照图1所示设置了内容区域,并且当前输出如图2所示。

欢迎您的帮助。谢谢。

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/balloonView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Title this is dummy text, this is dummy text, this is dummy text"
    android:textSize="13dp"
    android:textColor="@android:color/white"
    android:background="@drawable/balloon" />

image1

image2

image3

image4

1 个答案:

答案 0 :(得分:0)

我用9个补丁(将TextView添加到res > drawable中)对您的balloon.9.png进行了复制粘贴。

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/colorPrimary"
    android:padding="50dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/balloon"
        android:text="Title this is dummy text, this is dummy text, this is dummy text"
        android:textColor="@android:color/white"
        android:textSize="13dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/balloon"
        android:text="Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, Title this is dummy text, this is dummy text, this is dummy text"
        android:textColor="@android:color/white"
        android:textSize="13dp" />

    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/balloon"
        android:gravity="center"
        android:padding="40dp"
        android:text="Title this is dummy text, this is dummy text, this is dummy text"
        android:textColor="@android:color/white"
        android:textSize="13dp" />

</LinearLayout>

这是输出(来自仿真器): enter image description here