【发布时间】:2016-04-24 01:45:01
【问题描述】:
我制作了一个小应用程序,并且是 android 动画/过渡的新手。
我想要什么: 如果你按下一个按钮,背景(视图)应该滑出,另一个应该进来,但我不想开始其他活动,我只想改变现有的背景。
这正是我想要的:https://www.polymer-project.org/0.5/components/core-animated-pages/demos/simple.html (必须把左上角方框里的方框改一下才能看到)
我在其他帖子中读到了一些关于它的内容,但通常有启动另一个活动的解决方案..
如果你明白我的意思,给我一个提示或教程链接之类的东西会很好。
编辑 - 解决方案
我让它为我工作,我构建了一个完全符合我想要做的代码,我给出了所有答案 1up 并标记最后一个,因为它接近我所做的。 谢谢大家。
这个链接非常有用: https://github.com/codepath/android_guides/wiki/Animations(目前我发现的最好的动画教程)
Slide right to left Android Animations(xmls 从右到左,从上到下,...)
左转示例:
代码:
public void transitionleft(final View viewcome, final View viewgo){
animcome = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_right_in);
animgo = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_left_out);
animgo.setDuration(1000);
animcome.setDuration(1000);
animcome.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
viewcome.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animgo.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
viewgo.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
viewcome.startAnimation(animcome);
viewgo.startAnimation(animgo);
}
res/anim/slide_right_in 中的 XML 过渡
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="100%" android:toXDelta="0%" />
<alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="1.0" />
</set>
res/anim/slide_left_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate android:duration="5000" android:fromXDelta="0%" android:toXDelta="-100%"/>
<alpha android:duration="5000" android:fromAlpha="1.0" android:toAlpha="1.0" />
</set>
它是如何工作的: 我有 2 个视图,它们都具有屏幕尺寸(match_parent)。一个是可见的,另一个不可见。 然后你把可见的作为viewgo(因为这应该消失)和不可见的作为viewcome(因为这应该是新进来的人) 在动画开始时,viewcome 将设置为可见,因为它“滑入”。 动画完成后,viewgo 将不可见,因为它“滑出”。 这很简单,而且效果很好。
要改进动画,您可以使用 AnimatorSet 来同步两个动画 (set.playtogether()),但如果没有它,它对我也很有效。
【问题讨论】:
-
这正是我要找的!
标签: android animation view transition