如何通过viewflipper滑动特定区域?

时间:2012-05-30 10:23:36

标签: java android viewflipper

我想通过viewflipper滑动特定区域。这是此部分的图像。enter image description here

通过viewflipper我成功刷了这部分区域。这是我的代码:

/** FOR Swip the View on touch **/
@Override
public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        oldTouchValue = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: {
        // if(this.searchOk==false) return false;
        float currentX = touchevent.getX();
        if (oldTouchValue > currentX) {

            vf.setInAnimation(inFromRightAnimation());
            vf.setOutAnimation(outToLeftAnimation());
            vf.showNext();
            if (vf.getCurrentView().getId() == R.id.ln1) {

                left.setButtonDrawable(R.drawable.dot);
                middle.setButtonDrawable(R.drawable.doubledot);
                right.setButtonDrawable(R.drawable.doubledot);
                mostright.setButtonDrawable(R.drawable.doubledot);
            }
            if (vf.getCurrentView().getId() == R.id.ln2) {

                middle.setButtonDrawable(R.drawable.dot);
                left.setButtonDrawable(R.drawable.doubledot);

                right.setButtonDrawable(R.drawable.doubledot);
                mostright.setButtonDrawable(R.drawable.doubledot);

            }
            if (vf.getCurrentView().getId() == R.id.ln3) {

                right.setButtonDrawable(R.drawable.dot);
                middle.setButtonDrawable(R.drawable.doubledot);
                left.setButtonDrawable(R.drawable.doubledot);

                mostright.setButtonDrawable(R.drawable.doubledot);

            }
            if (vf.getCurrentView().getId() == R.id.ln4) {

                right.setButtonDrawable(R.drawable.doubledot);
                middle.setButtonDrawable(R.drawable.doubledot);
                left.setButtonDrawable(R.drawable.doubledot);

                mostright.setButtonDrawable(R.drawable.dot);

            }

        }
        if (oldTouchValue < currentX) {
            vf.setInAnimation(inFromLeftAnimation());
            vf.setOutAnimation(outToRightAnimation());
            vf.showPrevious();
            if (vf.getCurrentView().getId() == R.id.ln1) {

                left.setButtonDrawable(R.drawable.dot);
                middle.setButtonDrawable(R.drawable.doubledot);
                right.setButtonDrawable(R.drawable.doubledot);
                mostright.setButtonDrawable(R.drawable.doubledot);
            }
            if (vf.getCurrentView().getId() == R.id.ln2) {

                middle.setButtonDrawable(R.drawable.dot);
                left.setButtonDrawable(R.drawable.doubledot);

                right.setButtonDrawable(R.drawable.doubledot);
                mostright.setButtonDrawable(R.drawable.doubledot);

            }
            if (vf.getCurrentView().getId() == R.id.ln3) {

                right.setButtonDrawable(R.drawable.dot);
                middle.setButtonDrawable(R.drawable.doubledot);
                left.setButtonDrawable(R.drawable.doubledot);

                mostright.setButtonDrawable(R.drawable.doubledot);

            }
            if (vf.getCurrentView().getId() == R.id.ln4) {

                right.setButtonDrawable(R.drawable.doubledot);
                middle.setButtonDrawable(R.drawable.doubledot);
                left.setButtonDrawable(R.drawable.doubledot);

                mostright.setButtonDrawable(R.drawable.dot);

            }

        }
        break;
    }
    }
    return false;
}

// for the previous movement
public static Animation inFromRightAnimation() {

    Animation inFromRight = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, +1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromRight.setDuration(350);
    inFromRight.setInterpolator(new AccelerateInterpolator());
    return inFromRight;
}

public static Animation outToLeftAnimation() {
    Animation outtoLeft = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, -1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    outtoLeft.setDuration(350);
    outtoLeft.setInterpolator(new AccelerateInterpolator());
    return outtoLeft;
}

// for the next movement
public static Animation inFromLeftAnimation() {
    Animation inFromLeft = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, -1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    inFromLeft.setDuration(350);
    inFromLeft.setInterpolator(new AccelerateInterpolator());
    return inFromLeft;
}

public static Animation outToRightAnimation() {
    Animation outtoRight = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, +1.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    outtoRight.setDuration(350);
    outtoRight.setInterpolator(new AccelerateInterpolator());
    return outtoRight;
}

但问题是我的整个区域的touchevent工作。当我触摸这个屏幕的任何区域时,它会刷这个。如何完美地工作这个touchevent,以便当我只触摸这个特定的区域时,它不会滑动。请帮助。 :(

0 个答案:

没有答案