9 补丁图像不拉伸
9 patch image not stretching
我正在尝试使用 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
我用 9-patch 复制粘贴了你的 TextView
(作为 balloon.9.png
添加到 res > drawable
)并且有效。
这是我的布局:
<?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>
这是输出(来自模拟器):
我正在尝试使用 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
我用 9-patch 复制粘贴了你的 TextView
(作为 balloon.9.png
添加到 res > drawable
)并且有效。
这是我的布局:
<?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>
这是输出(来自模拟器):