单击按钮的径向菜单android? [英] Radial menu android with button click?

查看:20
本文介绍了单击按钮的径向菜单android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设计这样的菜单.

我尝试过动画,但它不保留按钮的位置.

I have tried animation but it does not retains position of buttons.

如果有人做过这种类型的菜单,请指导我.

if any one have done this type of menu please guide me.

任何帮助将不胜感激.

推荐答案

我最近创建了这个圆形菜单来添加到我最近的项目中.看起来像

I recently created this circular menu to add up in my recent project. It looks like

你需要的是创建一个新的视图并绘制这个视图,检查用户输入(他正在触摸的地方),设计一个反馈机制,例如,在我看来,如果用户触摸了 5 个弧中的任何一个,背景颜色变为天蓝色.这是我的 onDrawMethod 代码.

What you need is to create a new View and draw this view, check for the user inputs (where he is touching), design a feedback mechanism, for example, in my view, if user touches any of the 5 arcs, background color changes to skyblue. Here is my code for onDrawMethod.

protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub

        px = getMeasuredWidth()/2;     
        py = getMeasuredHeight();


        initial = 144;
        finalangle = 252;

        centerCircleradius  = 30;
        middleCircleRadius = 140;




            int init, fina;
            init = 160;    
            fina = 360;
            finalOVal.set(px-middleCircleRadius-4, py-middleCircleRadius-4, px+middleCircleRadius+4, py+middleCircleRadius+4);
            middleOval.set(px-middleCircleRadius, py-middleCircleRadius, px+middleCircleRadius, py+middleCircleRadius);
            while(init<fina)
            {
                circlePaint.setColor(colors[i]);
                canvas.drawArc(finalOVal,init,10,false, circlePaint);
                i++;
                if(i>=colors.length)
                {
                    i=0;
                }
                init = init + 10;

            }



            canvas.drawArc(middleOval, 180, 180, false, pencil);

            midInitial = 180;


            i=0;

            //Creating the first Arc
            if(arcTouched[0])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(0), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;

            if(arcTouched[1])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(1), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;

            if(arcTouched[2])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(2), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;
            //Creatring the second Arc

            if(arcTouched[3])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(3), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);
            midInitial+=36;

            if(arcTouched[4])
            {

                canvas.drawArc(middleOval, midInitial, 36, true, arcTouchedBack);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            else
            {
                canvas.drawArc(middleOval, midInitial, 36, true, middleCircleBody);
                canvas.drawArc(middleOval, midInitial, 36, true, pencil);
            }
            canvas.drawBitmap(bitmap.get(4), null, (putBitmapTo(midInitial, 36, 140, px, py)), null);           
            canvas.drawCircle(px, py-10, 40, pencil);
            canvas.drawCircle(px, py-10, 39, smallCircleCore);

            canvas.drawCircle(px, py-10, 35, bigArc);
            canvas.drawCircle(px, py-10, 20, smallCircleCore);

            canvas.drawCircle(px, py-10, 15, bigArc);
            canvas.drawLine(px-8, py-10, px+8, py-10, lineCore);

        canvas.save();
    }

您可能需要的一些参考资料.

Some reference that you might need.

bitmap -> 是一个包含图像的数组列表

bitmap -> is an arraylist that contains images

arcToched[] -> 是一个定义弧背景的数组,这个布尔数组的值在 onTouchEvent() 方法中被修改.

arcToched[] -> is an array that defines the background for arc, the values of this boolean array gets modified in onTouchEvent() method.

lineCore、smallCircleCore ..... 是油漆.

lineCore, smallCircleCore ..... are paints.

我知道这不是最好的方法,也不专业.我根据需要创建了这个菜单.在您更改角度计算之前,它无法以某种方式缩放.

I know this isn't the best way and not professional too. I created this menu as per need. Its not scale able in a way until you change the angle calculations.

此视图的灵感来自 Catch Notes 应用程序.我在创建此视图时面临的唯一麻烦是确定所接触的弧.我在这里使用的唯一动画和 Catch Notes 一样(圆形菜单扩展到比给定的大小多一点然后恢复正常).

This view is highly inspired from Catch Notes Application. The only trouble I face in creating this view was to determine the arc touched. The only animation I used in here are just like again Catch Notes (the one in which circular menu extends a bit more than given size then gets back normal).

这篇关于单击按钮的径向菜单android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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