Android的圈子菜单像抓注 [英] Android Circle Menu Like Catch Notes

查看:173
本文介绍了Android的圈子菜单像抓注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试做圆形菜单就像在这个程序。

I try to do circle menu like in this app.

在扩展模式,我得出这样的组件类似如下:

In "expanded" mode i draw this component like follows:

<RelativeLayout android:id="@+id/bigCircle">
<!--color full borders-->
    <my.custom.component android:id="@+id/middleCircle">
    <!--circle for buttons-->
         <RelativeLayout android:id="@+id/smallCircle">
           <!--minus button-->
         </RelativeLayout>
    </my.custom.component>
</RelativeLayout>

my.custom.component 我把8件圆使用 android.graphics.Path 与 android.graphics.Paint 和一些数学。
视觉上我有完全如屏幕截图所示。但是,当I $圆上的部件P $ PSS,我需要重新绘制这部分在另一种颜色来显示用户什么一些事情。

In onDraw method of my.custom.component i divide circle on 8 parts by using android.graphics.Path with android.graphics.Paint and some math.
Visually i have exactly as shown in the screenshot. But when i press on part of circle, i need redraw this part in another color to show user what something going on.

我怎么能重绘组件的画布,从画布上的另一部分切断由 android.graphics.Path 例如一部分。
换句话说,我知道是什么重绘的画布我应该做的OnDraw方法,我知道我可以展示可绘制画在Photoshop的一些位图,并有一些多屏的麻烦,我知道我可以决定哪些用户pressed一部分。但我不知道我可以选择画布的一部分,并重绘。

How i can redraw part of component's canvas cutting off from another part of canvas by android.graphics.Path for example.
In another word i know what redraw canvas i should do in onDraw method, i know that i can show some bitmap from drawables painted in photoshop and have some "multiscreen trouble", i know how i can determine part which user pressed. But i don't know how i can select part of canvas and redraw it.

推荐答案

开发赶上这里。如果我理解你的问题,你遇到麻烦了解如何专门绘制高亮/选择指示器上的圆形菜单的部分。

Developer of Catch here. If I'm understanding your issue, you're having trouble understanding how to specifically draw the highlight/selection indicator on a section of your circular menu.

虽然有很多人能实现它不同的方式,你倾向于(使用 android.graphics.Path )的是我们如何做的。在我们拍摄按钮的视图层次,有充当画布元素上选择高亮颜色(如果存在的的活跃选择)绘制。

While there are plenty of different ways one could implement it, what you're leaning towards (using android.graphics.Path) is how we did it. In the view hierarchy of our capture button, there's an element that serves as the canvas on which the selection highlight color (if there is an active selection) is drawn.

如果你有在布局一个类似的自定义查看,你可以复制像这样此行为。首先,你需要在路径定义选择一个特定的圆弧。使用 Path.addArc(RectF,浮动,浮动)我们可以得到比萨饼片形路径,我们需要:

If you had a similar custom View in your layout, you could duplicate this behavior like so. First, you'll need the Path that defines the selection for a particular circle segment. Using Path.addArc(RectF, float, float) we can get the pizza-slice-shaped path we need:

private Path getPathForSegment(float startAngle, float sweep) {
    Point center = new Point(getWidth() / 2, getHeight() / 2);
    RectF rect = new RectF(0f, 0f, getWidth(), getHeight());
    Path selection = new Path();
    selection.addArc(rect, startAngle, sweep);
    selection.lineTo(center.x, center.y);
    selection.close();
    return selection;
}

的getWidth()的getHeight()以上是封闭的自定义视图对象,所以他们定义边框包含在其上选择绘制圆。

The getWidth() and getHeight() above are for the enclosing custom view object, so they define the bounding box that contains the circle on which the selection is drawn.

然后,在你的自定义视图的的OnDraw(画布),如果你的code已确定的选择应绘制段:

Then, in your custom view's onDraw(Canvas), if your code has determined a selection should be drawn for a segment:

@Override
protected void onDraw(Canvas canvas) {
    // Assume one has the rest of these simple helper functions defined
    if (shouldDrawSelection()) {
        float startAngle = getStartAngleOfSelectedSegment();
        float sweep = getSweepAngle();
        Paint paint = getPaintStyleForSelectedSegment();
        Path path = getPathForSegment(startAngle, sweep);
        canvas.drawPath(path, paint);
    }

    // ...

    super.onDraw(canvas);
}

在你的code正在跟踪触摸的其他地区,只需拨打无效()在自定义视图,以便将重绘(或没有)的基础上,改变输入或状态选择路径。

In the other areas of your code that are tracking touches, just call invalidate() on the custom view so that it will redraw (or not) the selection path based on changes in input or state.

请记住,这是很好的做法,以避免的OnDraw荷兰国际集团的对象(),所以大部分这些积木(路径 S,油漆 S等)可以构造时间提前(或一次,上一次出现时)和重复使用。

Remember that it's good practice to avoid newing objects in onDraw(), so most of these building blocks (Paths, Paints, etc.) can be constructed ahead of time (or once, on first occurrence) and reused.

希望这是接近你是问!

这篇关于Android的圈子菜单像抓注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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