动画不流畅

发布于 2024-12-05 19:10:32 字数 2320 浏览 7 评论 0原文

我在我的应用程序中使用动画。我使用的动画是 slide_leftslide_right。我遇到了以下问题:向左滑动时显示的动画流畅且精细,但向右滑动时,动画不像向左滑动时显示的那么平滑。那么为什么会出现这个问题呢?这是我的代码,请检查是否有任何错误。

slide_left.xml 文件的代码

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="@android:integer/config_longAnimTime" />
</set>

slide_right.xml 的代码

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-150%p" android:toXDelta="0"
android:duration="@android:integer/config_longAnimTime" />
</set>

.java 文件的代码

public boolean onTouch(View v, MotionEvent e) 
{
    switch (e.getAction())
    {
        case MotionEvent.ACTION_DOWN:
        {
            //store the X value when the user's finger was pressed down
            m_downXValue = e.getX();
            break;
        }   
        
        case MotionEvent.ACTION_UP:
        {
            //Get the X value when the user released his/her finger
            float currentX = e.getX();
            
            // going forwards: pushing stuff to the left
            if (m_downXValue > currentX && currentX < 0)
            {                   
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.flipview);
                vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left));                
            }
            
            // going backwards: pushing stuff to the right
            if (m_downXValue < currentX && currentX > 100)
            {                   
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.flipview);                                     
                vf.setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));                                
            }                                       
            break;
        }
    }
    
    return true;
}

I use animation in my app. Animation that I use is slide_left and slide_right. I faced the following problem: animation shown while sliding left is smooth and fine but when I slide right, the animation is not as smooth as shown while sliding left. So why this problem occurs? Here is my code please check if there are any errors.

Code for slide_left.xml file

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="@android:integer/config_longAnimTime" />
</set>

Code for slide_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-150%p" android:toXDelta="0"
android:duration="@android:integer/config_longAnimTime" />
</set>

Code for .java file

public boolean onTouch(View v, MotionEvent e) 
{
    switch (e.getAction())
    {
        case MotionEvent.ACTION_DOWN:
        {
            //store the X value when the user's finger was pressed down
            m_downXValue = e.getX();
            break;
        }   
        
        case MotionEvent.ACTION_UP:
        {
            //Get the X value when the user released his/her finger
            float currentX = e.getX();
            
            // going forwards: pushing stuff to the left
            if (m_downXValue > currentX && currentX < 0)
            {                   
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.flipview);
                vf.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left));                
            }
            
            // going backwards: pushing stuff to the right
            if (m_downXValue < currentX && currentX > 100)
            {                   
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.flipview);                                     
                vf.setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));                                
            }                                       
            break;
        }
    }
    
    return true;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯沦落人 2024-12-12 19:10:32

将此代码放在左侧...

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="@string/duration"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="Duration" />
</set>

并将此代码放在右侧...

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="@string/duration"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="Duration" />
</set>

只需添加您的持续时间...

就可以了...

Put this Code for Left Side...

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="@string/duration"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="Duration" />
</set>

And Put this Code for Right Side...

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="@string/duration"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="Duration" />
</set>

in that just Add your Duration...

It's Work...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文