Need help drawing buttons around a circular path in Java code?

I can get the center point of the circle, so I want to draw some buttons around the center point of the circular motion, as you saw in this image http://i.6.cn/cvbnm/50/97/b0/e7ed11251c3069fea4130c74b3ecb10c.png , can you give me some tips, links to examples will become 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 can put the images in a circular way, but I could not implement the ontouch event or the onclick event for each image, and also centerX or centerY to find the edge of the screen, how to put the images in a wide area of ​​the screen.

+5
source share
2 answers
x = centerX + radius * cos(alpha)
y = centerY + radius * sin(alpha)

alpha 0 2 * PI.

.

+6

@Amadan, , imageViews , , , , 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));
    }


}

, , , centerX = 5, centery = 10, , , , ,

+1

All Articles