Просмотр анимации справа налево - программирование

Просмотр анимации справа налево

Я не могу добавить анимацию вида для раздутых макетов. Я использовал следующий фрагмент кода

pageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.right_to_left_anim.xml));

и xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
         android:shareInterpolator="false">
     <translate android:fromXDelta="0%" android:toXDelta="100%"
          android:fromYDelta="0%" android:toYDelta="0%"
         android:duration="700"/>

</set>

Есть ли что-то, чего я не вижу?

Спасибо.

4b9b3361

Ответ 1

Вот код скользящей анимации для просмотра.

1)inFromRightAnimation

    private 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(500);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        return inFromRight;
        }

 2)outToLeftAnimation   
    private 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(500);
    outtoLeft.setInterpolator(new AccelerateInterpolator());
    return outtoLeft;
    }

3)inFromLeftAnimation

    private 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(500);
    inFromLeft.setInterpolator(new AccelerateInterpolator());
    return inFromLeft;
    }

4)outToRightAnimation

    private 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(500);
    outtoRight.setInterpolator(new AccelerateInterpolator());
    return outtoRight;
    }

и теперь запустите анимацию в режиме просмотра

pageView.startAnimation(inFromRightAnimation());

Спасибо,

Ответ 2

Если вы пытаетесь анимировать представление при его первом создании, вам либо нужно установить свойство layoutAnimation XML, либо вызвать setLayoutAnimation().

Если вы просто хотите, чтобы ваше представление выглядело как движущееся, вам нужно TranslateAnimation; см. этот ответ: fooobar.com/questions/255796/... Также, если вы хотите повторить анимацию, вызовите setAnimationListener() и в onAnimationEnd() снова запустите анимацию.

Если вы пытаетесь перенести представление навсегда, см. это: http://www.clingmarks.com/how-to-permanently-move-view-with-animation-effect-in-android/400

Ответ 3

Я знаю, что вы уже приняли ответ. Но я думаю, что этот ответ будет полезен для кого-то, кто это читает. Вы можете попробовать удалить .xml, pageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.right_to_left_anim.xml));