播放动画补间动画的android中 [英] Playing tween animation in android
问题描述
我是相当新的编程和心里有一个问题。我想,其中水平条从屏幕的顶部移动到屏幕的底部,并比从底部到顶部与特定速度的动画效果。现在目前,我使用的帧动画,其中一系列的图像都打出了如酒吧从顶部移到底部出现了一个效果。
I'm fairly new to programming and have a question in mind. I want to make an animation effect in which a horizontal bar moves from the top of the screen to the bottom of the screen and than from the bottom to the top with a specific speed. Now currently, I'm using frame animation in which series of images are played which give an effect as if the bar is moving from the top to bottom.
现在我的问题是什么,我如何能够实现它通过补间动画,因为它会使用一个图片此效果的工作,因为我想要的。
Now what my question is how can I achieve it through tween animation as it will use just one image for this effect to work as I want.
感谢您提前。
推荐答案
您应该使用动画
功能吧。在资源为它创建一个新的文件夹
文件夹来保存所有类型的动画 XML
类。
You should use Animation
function for it. Create a new folder for it in resource
folder to save all types of animation xml
classes.
有关在底部动画的幻灯片,使用code:
For slide in bottom animation, use this code:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%p"
android:duration="@android:integer/config_longAnimTime"/>
对于在顶部动画的幻灯片,使用code:
For slide in top animation, use this code:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:toYDelta="0%p"
android:duration="@android:integer/config_longAnimTime" />
有关滑出底部动画,使用code:
For slide out bottom animation, use this code:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0"
android:duration="@android:integer/config_longAnimTime" />
有关滑出顶级动画,使用code:
For slide out top animation, use this code:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:toYDelta="100%p"
android:duration="@android:integer/config_longAnimTime" />
而在你的活动,初始化动画
全球第一,如:
Animation anim;
和得到你想要在的onCreate
喜欢的动画类型的ID:
And get id of the type of animation you want inside onCreate
like:
anim = (Animation) AnimationUtils.loadAnimation(Play.this,
R.anim.slide_in_bottom);
然后设置动画,当你需要调用它像:
And then set your animation when you need to call it like :
container.setAnimation(anim);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
MyTask();
container.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
container.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationStart(Animation animation) {
container.setVisibility(View.VISIBLE);
}
});
container.startAnimation(anim);
下面容器
是父布局即的LinearLayout
主 XML的
类。
这篇关于播放动画补间动画的android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!