onTouch返回InvalidCastException

时间:2011-08-22 11:21:21

标签: android

我用这段代码得到了一个InvalidCastException:

public boolean onTouch(View view, MotionEvent event) {
    if (!(view instanceof Card)) return false;
    int eventaction = event.getAction();
    Card card = (Card)view;
    int X = (int)event.getRawX();
    int Y = (int)event.getRawY();
    switch (eventaction) {
        case MotionEvent.ACTION_DOWN:
            card.setAlpha(128);
            card.bringToFront();
            SoundManager.playSound(1, 1);
            int rotation = (card.getRotation()-Card.ROTATION_HORIZONTAL) * -1;
            card.setRotation(rotation);
            break;
        case MotionEvent.ACTION_MOVE:
            card.setPosition(X - (card.getImage().getWidth()), Y - (card.getImage().getHeight()));
            break;
        case MotionEvent.ACTION_UP:
            card.setAlpha(255);
            SoundManager.playSound(2, 1);
            break;
    }
    return true;
}

类卡扩展了ImageView,这段代码在RelativeLayout中工作得很好,但在LinearLayout中却没有...有任何理由吗?

0 个答案:

没有答案