我正在创建绘画应用程序,并且使用了Drawingcanvas
类。与该类一起,我还使用了Shape类(circle, oval, rectangle and input text etc)
。我的问题是,当我在DrawingCanvas
类的if语句中使用所有形状时,每次都将一个错误(不可转换类型,无法强制转换"com.example.apex.myapplication.shape"
)到circle.oval,InputText等上。
case MotionEvent.ACTION_MOVE:
if (mCurrentOperation == Constants.OPERATION_DRAW_PENCIL || mCurrentOperation == Constants.OPERATION_ERASE) {
mBrushPath.lineTo(xPos, yPos);
} else if (mCurrentOperation == Constants.OPERATION_MOVE_VIEW)
{
if (mCanvasLeftBounds < xPos && xPos < mCanvasRightBounds && mCanvasTopBounds < yPos && yPos < mCanvasBottomBounds)
{
if (mShapeToMove instanceof Circle)
{
((Circle) mShapeToMove)
((Circle) mShapeToMove).setCenterX(xPos);
((Circle) mShapeToMove).setCenterY(yPos);