Android:我可以创建一个不是矩形的视图/画布,但例如。回合? [英] Android: can I create a view/canvas that is not rectangular, but e.g. round?

查看:170
本文介绍了Android:我可以创建一个不是矩形的视图/画布,但例如。回合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图是圆的,并悬停在( - >在z轴方向出来的屏幕)主要内容。当有人点击屏幕时,我想要选择主要内容,或者将视图悬停在上方,当它覆盖主视图时。



到目前为止,完美的。我有一个圆形项目在透明的画布上。这意味着你可以看到在那个圆圈之外的背景的一切。但是,你不能选择它,因为它仍然是悬停的画布,只是一个透明的油漆。



现在我想知道,要解决这个问题,如果它是

$

$

$

b
$ b

我添加了一个图像更好的解释我试图实现。

解决方案

据我所知 - 这是不可能的。我检查了 View.java 在Git.kernel.org,它是基于Rect类 - rects定义位置,大小,区域无效等(视图的几何形状是矩形的。 - 来自View.java中的注释)



对于Canvas类 - 它通常是通过Bitmap或GL构造的。位图是一个矩形(矩阵),所以画布似乎也代表一个矩形。如果使用GL,指定视口(也是一个矩形)。



这似乎是最明显的方法来检查传递给你的onTouch方法适合你的区域,如果他们不返回false。然后事件将传递到下面的视图,它应该处理事件。


I have a view that is round and hovering above (-> in z-axis direction coming out of the screen) the main content. When the someone taps the screen I want either the main content to be selected or the view hovering above, when it covers the main view.

So far that works perfectly. I have a round shaped item on a transparent canvas. Meaning you can see everything of the background that is outside of that circle. However, you cannot select it, because it is still the hovering canvas, just with a transparent paint.

Now I'm wondering, to solve this issue, if it is possible to make the view/canvas itself round shaped?


Update

I added an image for better explanation what I try to achieve.

解决方案

As far as I know - it is impossible. I have checked the sources of View.java at git.kernel.org and it is based on Rect class - rects define position, size, regions to invalidate etc. ("The geometry of a view is that of a rectangle." - from the comments in View.java)

As for Canvas class - it is usually constructed over Bitmap or GL. Bitmap is definitely a rectange (a matrix), so canvas seems to represent a rectange too. If using GL a viewport is specified (which is a rectangle, too).

It seems to be the most obvious way to check if the coordinates passed to your onTouch() method fit you region and return false if they don't. Then the event will be passed to the View below and it should process the event.

这篇关于Android:我可以创建一个不是矩形的视图/画布,但例如。回合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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