在下面的图片上创建buttons
的最佳方法是什么?
答案 0 :(得分:1)
请参阅https://code.google.com/p/radial-menu-widget/或How To Create a Rotating Wheel Control?或此https://github.com/VadimDev/android-seekbar-like-ipod-clickwheel或自行制作
protected void onDraw(Canvas canvas){ // TODO自动生成的方法存根
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();
}
答案 1 :(得分:0)
我建议构建一个自定义组件并覆盖onTouch(View, MotionEvent)
。在该方法中,做一些基本的数学运算来检查触摸是否在圆形区域内,当方法消耗触摸事件时返回true
。
当您不想使用触摸事件时,不要忘记允许其他触摸侦听器通过返回false
进行传播。