在图中的Java code中的圆形路径按钮周围需要帮助? [英] Need Help in drawing buttons around the circular path in Java code?

查看:108
本文介绍了在图中的Java code中的圆形路径按钮周围需要帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以得到圆形的中心点,所以我想提请绕圆形的中心点一些按钮,当你在这个形象<一看到href="http://i.6.cn/cvbnm/50/97/b0/e7ed11251c3069fea4130c74b3ecb10c.png">http://i.6.cn/cvbnm/50/97/b0/e7ed11251c3069fea4130c74b3ecb10c.png ,你可以给我一些建议,链接的例子将更加有用。这是我的code

编辑:

 公共类drawCirPicture延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(新SampleView(本));
}

私有静态类SampleView扩展视图{
    私人位图mBitmap;




    公共SampleView(上下文的背景下){
        超(上下文);
        setFocusable(真正的);

        InputStream的是= context.getResources()openRawResource(android.R.drawable.sym_call_outgoing)。
        mBitmap = BitmapFactory.de codeStream(是);

    }

    @覆盖保护无效的OnDraw(帆布油画){
        canvas.drawColor(Color.GRAY);

        涂料P =新的油漆();
        浮centerY = 200;
        浮动的centerX = 130;

       双阿尔法= 0,楔= 0;
       双PI = Math.PI;

        浮动的x,y;

        INT半径= 55;

        为(阿尔法= 0,楔= 2 * PI / 4;阿尔法2 * PI;阿尔法+ =楔)
        {
            X =(浮点)(的centerX +半径* Math.cos(阿尔法));
            Y =(浮点)(centerY +半径* Math.sin(阿尔法));
            canvas.drawBitmap(mBitmap,X,Y,p)的;
        }


    }

    @覆盖
    公共布尔的onTouchEvent(MotionEvent事件){
        // TODO自动生成方法存根
        返回super.onTouchEvent(事件);
    }

    @覆盖
    公共布尔performClick(){
        // TODO自动生成方法存根
        返回super.performClick();
    }
    }
}
 

我能够把图像中的圆形路径,但我没能实现ontouch事件或每幅图像的onclick事件,也是的centerX或centerY定位在屏幕的边缘,如何把图像的屏幕的宽域。

解决方案

  X =的centerX +半径* COS(阿尔法)
Y = centerY +半径*罪(阿尔法)
 

其中,字母 0和 2 * PI 之间。

三角很酷。

i can get a central point of the circular,so i want to draw some buttons around the central point of the circular,as you seen in this image http://i.6.cn/cvbnm/50/97/b0/e7ed11251c3069fea4130c74b3ecb10c.png ,can you give me some advice,Links to examples will be more useful. This is My code

Edit:

public class drawCirPicture extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new SampleView(this));
}

private static class SampleView extends View {
    private Bitmap mBitmap;




    public SampleView(Context context) {
        super(context);
        setFocusable(true);

        InputStream is = context.getResources().openRawResource(android.R.drawable.sym_call_outgoing);
        mBitmap = BitmapFactory.decodeStream(is);

    }

    @Override protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.GRAY);

        Paint p = new Paint();
        float centerY = 200;
        float centerX=130;

       double alpha = 0,wedge=0;
       double PI=Math.PI;

        float x,y;

        int radius=55;

        for (alpha = 0, wedge = 2 * PI / 4; alpha < 2 * PI; alpha += wedge)
        {
            x = (float) (centerX + radius * Math.cos(alpha));
            y = (float) (centerY + radius * Math.sin(alpha));
            canvas.drawBitmap(mBitmap, x, y, p);
        }


    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        return super.onTouchEvent(event);
    }

    @Override
    public boolean performClick() {
        // TODO Auto-generated method stub
        return super.performClick();
    }
    }
}

i am able to put images in the circular path, but i was not able to implement ontouch event or onclick event of every image, and also the centerX or centerY locate the edge of the screen ,how to put the images to the wide area of the screen.

解决方案

x = centerX + radius * cos(alpha)
y = centerY + radius * sin(alpha)

Where alpha is between 0 and 2 * PI.

Trigonometry is cool.

这篇关于在图中的Java code中的圆形路径按钮周围需要帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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