我可以得到圆的中心点,所以我想在圆的中心点周围绘制一些按钮,如您在此图像http://i.6.cn/cvbnm/50/97/b0/e7ed11251c3069fea4130c74b3ecb10c.png中看到的,您能给我一些建议吗,指向示例的链接会更有用。这是我的代码
编辑:
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();
}
}
}
我可以将图像放置在圆形路径中,但是我无法实现每个图像的ontouch事件或onclick事件,并且centerX或centerY可以定位屏幕的边缘,如何将图像放置在屏幕。
最佳答案
x = centerX + radius * cos(alpha)
y = centerY + radius * sin(alpha)
其中
alpha
在0到2 * PI
之间。三角函数很酷。