圆形按钮圆形、按钮

2023-09-07 16:27:54 作者:折耳兔叽耶

我想有这样的事情五个按钮,一个按钮被其他四个按键包围。就像这样:

I want to have something like this five buttons, one button surrounded by four other buttons. Just like this:

我知道,与Android,我们只能有方型意见,如何才有可能做到这一点? OpenGL或东西吗?任何人有相关的东西有任何联系?基本上我想要弯曲按钮,紧靠在一起。

I know that with Android that we can only have square type views so how would it be possible to do this? OpenGl or something? Anyone have any links to something related? Basically I want curved buttons that are close together.

推荐答案

我的猜测是,在一天结束的时候它会更容易做到这一点自定义视图。

My guess is that at the end of the day it will be easier to do this in a custom view.

但是,如果你想用股票的看法,我建议如下。首先,使用一个RelativeLayout的容器在一个2x2格排列的四个按钮之外。然后,使其重叠在中心格栅位置的中央按钮。把中心按钮在较高的Z比四周围按钮(靠近用户)。然后用透明的按钮图像的一部分,让他们看起来像你想要的。然后,(希望)尝试一下。如果Z次序是正确的,中间的按钮将捕获,否则去了其他四个按钮中的一个水龙头。

But if you want to use stock views, I'd suggest the following. First, use a RelativeLayout container to arrange the four outside buttons in a 2x2 grid. Then position the center button so it overlaps the grid in the center. Put the center button at a higher Z (closer to the user) than the four surrounding buttons. Then use transparency as part of the button images to get them to look like you want. Then (hopefully) try it out. If the Z order is right, the center button will capture taps that would otherwise have gone to one of the other four buttons.

这实际上将不作为是工作,因为中间的按钮广场将侵入周围的广场。我不知道它是否会工作,但你可以尝试用按钮片另一个网格替换中央按钮。该网格将有除非中央按钮图像重叠网格单元空位置。你必须让这个罚款足以避免侵入到外的按钮图像。

This actually won't work as is, because the center button square will intrude into the surrounding squares. I don't know if it would work, but you can then try replacing the center button with another grid of button "pieces". The grid would have empty positions except where the center button image overlaps the grid cell. You'll have to make this fine enough to avoid intruding into the outer button images.

修改

我突然想到,也许你可以用组 TouchDelegate 的对象。正如我在第一次描述你会排列按钮,但要只的父的容器点击。这将用五年 TouchDelegate s到找出哪个按钮(如果有的话)是水龙头下的坐标。不幸的是, TouchDelegate 矩形工作严重的地区,这让我们在哪里开始。但是,你可以拆取 TouchDelegate 来源和定义自己的版本,接受某种形式的一般形状类,而不是只是一个矩形的。 (形状类必须具有相当于 Rect.contains()来测试一击。没有什么内置了Android的,但你可以很容易地编写自己的类具体的形状,你有。)

It occurred to me that perhaps you could do this with a group of TouchDelegate objects. You would arrange the buttons as I described at first, but make only the parent container clickable. It would use five TouchDelegates to find out which button (if any) was under the tap coordinates. Unfortunately, TouchDelegate only work with Rect hit regions, which leaves us where we started. However, you could cannibalize the source of TouchDelegate and define your own version that accepts some sort of general shape class instead of just a Rect. (The shape class would have to have the equivalent of Rect.contains() to test for a hit. There's nothing built into Android, but you could easily write your own classes for the specific shapes you have.)

您可以直接把命中和代表团逻辑在父容器视图简化codeA位,但它是清洁的,我想,有分离出来的情况下从容器处理一个可重用的委托类本身。

You could simplify the code a bit by putting the hit and delegation logic directly in the parent container view, but it would be cleaner, I think, to have a reusable delegate class that separates out the event handling from the container itself.