机器人 - 允许的背景可拉伸只有一个特定的区域伸展 [英] Android - allow only a specific area of a background drawable to stretch

查看:163
本文介绍了机器人 - 允许的背景可拉伸只有一个特定的区域伸展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人如何去创建一个查看有三角形孔的边界呢?

How does one go about creating a View that has boundaries with triangular perforations ?

输入图像的描述在这里

我一直在使用的背景可绘制实现这一目标为止。这一工程时,查看尺寸是固定的。现在我有一种情况:查看的不是恒定的,所以我需要对飞行的高度变量。我不能使用背景绘制一个固定的高度了。

I've been using background drawables to achieve this so far. That works when the dimensions of the View are fixed. Now I have a situation where the height of the View is not constant, so I need to have the height variable on the fly. I can't use a background drawable with a fixed height anymore.

下面是原来的背景绘制:

Here is the original background drawable:

输入图像的描述在这里

这是最后的查看需要如下:

输入图像的描述在这里

看待同样的问题的另一种方式是,我们可以允许来拉伸图像的中心不扭曲的界限?如果我们能做到这一点,我们可以使用现有的绘制作为背景。

Another way of looking at the same problem is, can we allow the center of the image to stretch without distorting the boundaries ? If we could do this, we could use the existing drawable as a background.

如何才能实现这一目标?之前有没有其他人遇到这个问题?该框架是否有处理这一类问题的存在方式?

How can this be achieved ? Has anyone else faced this problem before ? Does the framework have an existing way of dealing with this class of problems ?

推荐答案

使用普通图像代替,就可以生成一个九补丁PNG。

Instead of using a normal image, you can generate a nine-patch png.

使用 简单九补丁生成 这一点。

Use Simple Nine-patch Generator for this.

的技巧是黑线左侧。这告诉Android的PNG是垂直扩展沿着这个区域。

The trick is the black line on the left side. That tells Android that the png is vertically expandable along this area.

请参见下面的例子:

九修补程序示例

将它保存为一个九补丁,格式imagename.9.png

Save it as a nine-patch, in the format imagename.9.png

这篇关于机器人 - 允许的背景可拉伸只有一个特定的区域伸展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆