带有九个补丁背景的文本视图周围的填充没有视觉效果

发布于 2024-10-15 07:27:25 字数 771 浏览 7 评论 0原文

我试图创建基于文本视图的类似吐司的控件,并且我发现文本视图的行为非常奇怪,如果它有九个可绘制的补丁作为背景。

这是 xml 定义:

<by.pplware.view.QuickInfo
    android:id="@+id/quickinfo"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:padding="20px"
    android:textSize="20px"
    android:textStyle="bold"
    android:typeface="serif"
    android:background="#FFFF0000"
/>

这是带有彩色背景的文本视图: 在此处输入图像描述

这是具有可绘制背景的文本视图: 在此处输入图像描述

据我了解,在 ninepatch 背景的情况下,android 会使填充透明并仅使用可绘制对象作为文本背景。但我想将填充包含到覆盖有 ninepatch 背景的区域中。

这个问题有什么解决办法吗?

Im trying to create toast like control based on textview, and i found very strange behavior of textview in case when it have nine patch drawable as background.

This is xml definition:

<by.pplware.view.QuickInfo
    android:id="@+id/quickinfo"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:padding="20px"
    android:textSize="20px"
    android:textStyle="bold"
    android:typeface="serif"
    android:background="#FFFF0000"
/>

this is textview with color background:
enter image description here

this is textview with drawable background :
enter image description here

As i understand, in case of ninepatch background android make padding transparent and use drawable only as background for text. But I want to include padding into area covered with ninepatch background.

Is there any solution for this issue ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裂开嘴轻声笑有多痛 2024-10-22 07:27:25

尝试以下任一方法:

  1. 通过“android:background”xml 属性而不是通过编程方式设置背景 ninepatch;这与 XML 定义的填充配合。
  2. 如果您需要以编程方式设置背景,请尝试在设置背景后重新设置填充(如果您设置填充然后设置背景,我假设在 ninepatch 本身中定义的填充会覆盖它)。
  3. 避免整个问题,只需在 nine-patch 图像中设置填充区域即可本身(即右侧和底部的黑条)。

Try any of these:

  1. Set the background ninepatch via the "android:background" xml property instead of programatically; this cooperates with XML-defined padding.
  2. If you need to set the background programatically, try to re-set the padding after setting the background (if you set the padding then set the background, I'd assume the padding defined in the ninepatch itself overrides it).
  3. Avoid the entire issue and just set the padding areas in your ninepatch image itself (that's the right and bottom black bars).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文