所以我用动画的动画视图:请查看动画在最终动画中的位置
<?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:duration="1000"
android:fromYDelta="0%"
android:toYDelta="-75%" />
</set>
它在视觉上我想要的,但我也想冻结这个动画的结果。就像我需要以某种方式得到结果布局参数(或其他东西?)后动画,并将其设置为布局。假设布局Y坐标从0变为100,但我并不知道什么是起始坐标和结果坐标。我需要得到结果坐标并将其设置为布局因为如果不这样做,动画布局返回到其初始位置,但我需要使它保持在新位置而不是返回。另外我需要2.3.x兼容解决方案。
更新1
我也试过NineOldAndroids:
ObjectAnimator.ofFloat(rootWrapper, "translationY", -rootWrapper.getHeight()*75/100).start();
这个动画的观点和看法停留在动画的位置 - 这就是正是我想达到的。
但是,所有控件都保持虚拟位置。即使你的布局只能看到它底部的25%,如果我点击那个空白的屏幕区域,然后按钮的onClick触发(其中有b4动画),剩余75%的屏幕看起来是空的。如果设置了xml-animtaions,也会发生同样的情况
animation.setFillAfter(true);
如何解决该问题?所有的控件必须随着视图移动。
更新2
代码:
public void showAbout(){
final Animation animShow = AnimationUtils.loadAnimation(this, R.anim.about_in_from_bottom);
animShow.setFillAfter(true);
//ObjectAnimator.ofFloat(rootWrapper, "translationY", -rootWrapper.getHeight()*75/100).start();
animShow.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
LinearLayout.LayoutParams rootlp = (LinearLayout.LayoutParams) rootWrapper.getLayoutParams();
Log.i(this,"rootlp: h: "+rootlp.topMargin+ "/w: "+rootlp.bottomMargin);
rootlp.topMargin = -rootlp.height*75/100;
rootWrapper.setLayoutParams(rootlp);
}
});
rootWrapper.startAnimation(animShow);
}
我得到了这个问题 - rootlp.height
返回0的Cuz它像MATCH_PARENT或喜欢。它不会返回REAL像素,而是一些代表某些常量的值!所以看起来我有两个玩.getViewTreeObserver().addOnGlobalLayoutListener
。
好吧,我通过getViewTreeObserver()获得了rootWrapper的真正高度。现在使用公式rootlp.topMargin = -rootlp.height*75/100;
我收到了更多问题。
1)动画View之后另外移动(由于设置LP)。
2)动画视图包含的控件(必须随父视图一起向上移动的按钮)虚拟地停留在它们的位置(它们不可见但可点击)!在视觉上,这些控件随着动画视图向上移动,我无法触及它(它离开屏幕)。但是,如果我点击区域,他们之前动画相应onClick()触发!多么有趣!
UPDATE 3
最后我达到了我的目标!问题在于移动View的子容器。我在想,如果我移动一些视图,那么它的所有子视图也在移动。但事实并非如此,我必须在动画完成后手动移动子视图以修复幽灵按钮。
你为什么试图在动画之后得到LayoutParams?你想让视图停留在动画位置吗? –
是的,正是我想要的2do。 – Stan
那么看到我的anser并使用setFillAfter(); –