是否有可能掩盖Android的视图? [英] Is it possible to mask a View in android?
问题描述
是否有可能掩盖看法?举例来说,如果我有一个要求列表视图是一个椭圆形的开口内可见一个设计。有没有一种方法来创建一个视图口罩?叫别的东西吗?因为所有的引用我发现在Android的文档掩蔽所谈论的掩盖画布对象或绘制。但我不觉得像做一个列表视图的互动对象的可绘制的将是一个不错的办法。这只是一个限制,以应对现在?
Is it possible to mask views? For example, if I have a design that calls for a List View to be visible within an oval shaped opening. Is there a way to create a mask for a view? Is it called something else? Because all the references I find to masking in the android docs are talking about masking a canvas object or drawable. But I don't think making a drawable of an interactive object like a list View would be a good approach. Is this just a limitation to deal with for now?
推荐答案
是的,它是 - 你必须重写视图的绘制方法 - 即:
Yes, it is - you have to override the drawing method of your view - i.e:
......
final Path path = new Path();
path.addRoundRect(new RectF(0,0,getWidth(),getHeight()),10,10,Direction.CW);
......
@Override
protected void dispatchDraw(Canvas canvas){
canvas.clipPath(path);
super.dispatchDraw(canvas);
}
这将吸引你的看法只有在边界由路径设置的。
this will draw your view only in the boundaries set by path.
这篇关于是否有可能掩盖Android的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!