简体   繁体   English

Android:三角形作为XML可绘制对象

[英]Android: triangle as an XML drawable

I would like to include a bottom right triangle on the background of each item in a listview. 我想在列表视图中的每个项目的背景上包括一个右下角的三角形。

右下角的三角形

I can achieve this using nine-patch images: 我可以使用九个补丁图像实现此目的:

九片

But, there can be different possible colors, so I would like to do this with XML drawables, so that I can easily add more colors. 但是,可能有不同的颜色,因此我想使用XML drawable进行此操作,以便可以轻松添加更多颜色。

My questions are 2: 我的问题是2:

1) How I can draw triangles as XML drawables ? 1) 如何将三角形绘制为XML可绘制对象 (I have realized that the triangle is not one of the possible drawing shapes in Android) (我已经意识到三角形不是Android中可能的绘图形状之一)

2) In case I manage to achieve a triangle drawable, how can I force that drawable to say at the bottom right background ? 2)如果我设法实现了三角形可绘制对象, 如何强制该可绘制对象在右下角的背景下显示 (with nine-patch images is pretty easy, but I don't know how to do the same with drawables) (使用九个补丁的图像非常简单,但是我不知道如何对可绘制对象执行相同的操作)

1) If there is no need for scaling then you could simply take your ninepatch drawable and recolor it. 1)如果不需要缩放,则可以简单地将您的ninepatch可绘制对象重新着色。 For example if your base triangle had transparent background and the triangle was white you could do something like this to color it into red: 例如,如果您的基本三角形具有透明背景,而三角形是白色,则可以执行以下操作将其颜色变为红色:

NinePatch ninePatch;
NinePatchDrawable drawable = new NinePatchDrawable(ninePatch);
drawable.setColorFilter(Color.RED, Mode.MULTIPLY);

2) Solved since you know how to do it with ninepatches 2)解决了,因为您知道如何使用ninepatches来解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM