从右到左查看动画 android [英] View animation right to left android

查看:28
本文介绍了从右到左查看动画 android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法为膨胀的布局放置视图动画.我使用了以下代码片段

I am not able to put view animation for inflated layouts. I used the following code snippet

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>

我有什么遗漏吗?

谢谢.

推荐答案

这里是视图滑动动画的代码.

Here is the code for the sliding animation for view.

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());

谢谢,

这篇关于从右到左查看动画 android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆