开发者

android: disable clicks from ViewSwitcher's inactive child view

I have a custom ViewSwitcher with a flip animation. The problem is that the v开发者_运维百科iew that's not currently shown (that contains child buttons) is intercepting the clicks from the active view. I've tried to set the visibility to invisible or gone (didn't work), I tried iterating through all child view and setting setClickable(false) and that didn't work.

Maybe I'm applying my changes in the wrong place? Below is the relevant sections of my code.

public class ViewFlip3D extends ViewSwitcher {
    // switches views
    public void flip() {
        float centerX = getWidth() / 2.0f;
        float centerY = getHeight() / 2.0f;

        Flip3D animOut = new Flip3D(-90, 0, centerX, centerY);
        animOut.setDuration(500);
        animOut.setInterpolator(new AccelerateInterpolator());
        animOut.setFillAfter(true);

        Flip3D animIn = new Flip3D(0, 90, centerX, centerY);
        animIn.setDuration(500);
        animIn.setInterpolator(new DecelerateInterpolator());
        animIn.setFillAfter(true);

        animIn.setAnimationListener(new ShowNextView(this, animOut));

        ViewGroup view = (ViewGroup) getCurrentView();

        // Disable clicks here!
        // like: view.DisableClicksFromAllChildViews();

        view.startAnimation(animIn);
    }

    private final class ShowNextView implements Animation.AnimationListener {
        public void onAnimationEnd(Animation animation) {
            container.showNext();
            ViewGroup view = (ViewGroup) container.getCurrentView();
            view.startAnimation(flipin);

            // Enable clicks here!
            // like: view.EnableClicksFromAllChildViews();
        }
    }
}


Remove fill after or call clearAnimation when you want the view out of the way.

If none of these suit your needs you can recursively loop the children and set clickable to false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜