显示动画效果时出现问题

时间:2011-09-21 06:28:08

标签: android

我在我的应用程序中使用了动画,我使用的动画是slide_left和slide_right.But问题是,向左滑动时显示的动画是平滑而精细但是当我向右滑动时,动画不像向左滑动时显示。那么为什么会出现这些问题。我已经发给你我的代码,请检查是否有任何错误..

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;
}

1 个答案:

答案 0 :(得分:0)

将此代码放入左侧......

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

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

它的工作......