开发者

Need Help in drawing buttons around the circular path in Java code?

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(savedInstance开发者_如何学JAVAState);
    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.


thank you @Amadan, you give me a clue, when i want to put imageViews or buttons to the view,i found very hard,so at last i used the AbsoluteLayout:

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));
    setContentView(R.layout.main);
    AbsoluteLayout ab =(AbsoluteLayout) findViewById(R.id.a1);

    float centerY = 200;
    float centerX=130;

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

    float x,y;

    int radius=55;


    InputStream is = getResources().openRawResource(R.drawable.ic_jog_dial_unlock);
    Bitmap  mBitmap = BitmapFactory.decodeStream(is);

    for (alpha = 0, wedge = 2 * PI / 5; 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);
        ImageView iv =new ImageView(this);
        iv.setImageBitmap(mBitmap);
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(drawCirPicture.this, "a", 1000).show();
            }
        });
        ab.addView(iv,new AbsoluteLayout.LayoutParams(mBitmap.getWidth(), mBitmap.getHeight(),(int) x,(int) y));
    }


}

it can solve my question,the fault is at present i cannot deal with the boundary,for example when centerX= 5 ,centery=10,the effect not my need,i need to further work ,i want you can give more clue ,thank you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜