Android 动画不是平滑的
我在我的应用程序中使用动画。我使用的动画是Android 动画不是平滑的,android,android-animation,Android,Android Animation,我在我的应用程序中使用动画。我使用的动画是slide\u left和slide\u right。我面临以下问题:向左滑动时显示的动画平滑而精细,但向右滑动时,动画不如向左滑动时显示的平滑。那么为什么会出现这个问题呢?这是我的代码,请检查是否有任何错误 幻灯片_left.xml文件的代码 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schema
slide\u left
和slide\u right
。我面临以下问题:向左滑动时显示的动画平滑而精细,但向右滑动时,动画不如向左滑动时显示的平滑。那么为什么会出现这个问题呢?这是我的代码,请检查是否有任何错误
幻灯片_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>
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;
}
幻灯片_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文件的代码
<?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>
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;
}
public boolean onTouch(视图v,运动事件e)
{
开关(如getAction())
{
case MotionEvent.ACTION\u DOWN:
{
//当按下用户的手指时,存储X值
m_downXValue=e.getX();
打破
}
case MotionEvent.ACTION\u UP:
{
//获取用户释放手指时的X值
float currentX=e.getX();
//向前:把东西推到左边
如果(m_downXValue>currentX&¤tX<0)
{
ViewFlipper vf=(ViewFlipper)findViewById(R.id.flipview);
vf.setInAnimation(AnimationUtils.loadAnimation(这个,R.anim.slide_左));
}
//倒退:把东西往右边推
如果(m_downXValue100)
{
ViewFlipper vf=(ViewFlipper)findViewById(R.id.flipview);
setAnimation(AnimationUtils.loadAnimation(这个,R.anim.slide_right));
}
打破
}
}
返回true;
}
将此代码放在左侧
<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>
在这方面,只需添加您的持续时间
这是工作…把这些放在里面或外面让我们