【问题标题】:9 patch image not stretching9 补丁图像不拉伸
【发布时间】:2019-03-08 21:17:49
【问题描述】:

我正在尝试使用 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了吗?应该是这样的:image.9.png
  • 是的,我做了“balloon.9.png”
  • 将您的 9-patch 图片添加到帖子中。
  • 添加到图片 4

标签: android kotlin nine-patch


【解决方案1】:

我用 9-patch 复制粘贴了你的 TextView(添加到 res &gt; drawableballoon.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>

这是输出(来自模拟器):

【讨论】:

  • 感谢您的回答。实际上,当我为视图膨胀时,我发现自己使用 LayoutParams 设置了绝对大小,这就是原因。我的坏...
猜你喜欢
  • 1970-01-01
  • 2012-04-15
  • 1970-01-01
  • 1970-01-01
  • 2016-07-27
  • 2011-05-15
  • 2013-08-02
  • 2016-11-22
相关资源
最近更新 更多