2

TranslateAnimation を使用してボタンを移動すると正常に動作しますが、アニメーションが開始される前に奇妙なちらつきが現れます。短時間、アニメーション ビューが実際よりも高い位置に移動します。その後、ビューを通常の位置に戻し、アニメーションを開始しました。

RelativeLayout を使用して 7 つのボタンを移動します。

public void moveView(final int rotationType) {
    AnimationSet animationList[] = new AnimationSet[buttonAmount];
    for (int i = 0; i < buttonAmount; i++) {
        AnimationSet animationsSet = new AnimationSet(false);
        animationsSet.setFillAfter(true);
        boolean visible = true;
        boolean hide = false;
        boolean show = false;
        ImageButton button = buttons.get(i);

        int position = i + movementCount;

        if (position < 0) {
            position = getLastButtonId();
        } else if (position > getLastButtonId()) {
            position = position - buttonAmount;
        }
        int cL = getDP(leftCoord.get(position));
        int cB = getDP(bottomCoord.get(position));

        // TODO left right

        if (rotationType == RIGHTBUTTON) {
            position--;
        } else if (rotationType == LEFTBUTTON) {
            position++;
        }

        if (position < 0) {
            position = getLastButtonId();
        } else if (position > getLastButtonId()) {
            position = position - buttonAmount;
        }
        int nL = getDP(leftCoord.get(position));
        int nB = getDP(bottomCoord.get(position));
        int left = cL - nL;
        int bot = cB - nB;
        long time = 1000;

        if (rotationType == LEFTBUTTON) {
            if (cL == getDP(leftArrowLeft) && cB == getDP(leftArrowBottom)) {
                hide = false;
                visible = true;
                show = true;
            }
            if (nL == getDP(leftArrowLeft) && nB == getDP(leftArrowBottom)) {
                hide = false;
                visible = false;
                time = 0;
            }

            if (nL == getDP(rightArrowLeft)
                    && nB == getDP(rightArrowBottom)) {
                hide = true;
            }
        } else

        if (rotationType == RIGHTBUTTON) {
            if (cL == getDP(rightArrowLeft)
                    && cB == getDP(rightArrowBottom)) {
                hide = false;
                visible = true;
                show = true;
            }
            if (nL == getDP(leftArrowLeft) && nB == getDP(leftArrowBottom)) {
                hide = true;
            }

            if (nL == getDP(rightArrowLeft)
                    && nB == getDP(rightArrowBottom)) {
                hide = false;
                visible = false;
                show = false;
                time = 0;
            }
        }

        TranslateAnimation trans = new TranslateAnimation(left, 0, bot, 0);

        final int l = nL;
        final int b = nB;
        final ImageButton ib = button;
        final boolean isVisible = visible;
        final boolean isHide = hide;
        final boolean isShow = show;
        final int count = i;
        final RelativeLayout layout = main;
        button.clearAnimation();
        trans.setAnimationListener(new AnimationListener() {
            RelativeLayout.LayoutParams params;

            @Override
            public void onAnimationStart(Animation animation) {
                params = new RelativeLayout.LayoutParams(
                        LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
                params.leftMargin = l;
                params.topMargin = b;
                ib.setLayoutParams(params);

                if (isVisible) {
                    int tag = (Integer) ib.getTag();
                    ib.setImageResource(resourcesList[tag]);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (!isVisible) {
                    ib.setImageDrawable(null);
                }
            }
        });

        trans.setDuration(time);
        animationsSet.addAnimation(trans);
        if (show) {
            Animation animShow = new AlphaAnimation(.0f, 1f);
            animShow.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    // ib.setVisibility(View.VISIBLE);
                    // buttons.get(count).setVisibility(View.VISIBLE);
                }
            });
            animShow.setDuration(1000);
            animationsSet.addAnimation(animShow);
        } else if (hide) {
            Animation hideShow = new AlphaAnimation(1.0f, .0f);
            hideShow.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                }
            });
            hideShow.setDuration(1000);
            animationsSet.addAnimation(hideShow);

        }
        button.startAnimation(animationsSet);
    }

    if (rotationType == RIGHTBUTTON) {
        movementCount--;
    } else if (rotationType == LEFTBUTTON) {
        movementCount++;
    }

    if (movementCount < 0) {
        movementCount = getLastButtonId();
    } else if (movementCount > getLastButtonId()) {
        movementCount = 0;
    }
}
4

0 に答える 0