开发者

Animation is not smooth

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:d开发者_运维技巧uration="@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;
}


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...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜