动画方法applyTransformation不会触发,直到我点击任何布局 [英] Animation method applyTransformation not triggered until I click any layout
问题描述
这是如此怪异,我有这个动画code:
This is so weird, I've this animation code:
public class ExpandAnimation extends Animation {
private View mAnimatedView;
private MarginLayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mWasEndedAlready = false;
/**
* Initialize the animation
* @param view The layout we want to animate
* @param duration The duration of the animation, in ms
*/
public ExpandAnimation(View view, int duration) {
setDuration(duration);
mAnimatedView = view;
mViewLayoutParams = (MarginLayoutParams) view.getLayoutParams();
mMarginStart = mViewLayoutParams.rightMargin;
mMarginEnd = (mMarginStart == 0 ? (0- view.getWidth()) : 0);
view.setVisibility(View.VISIBLE);
mAnimatedView.requestLayout();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
if (interpolatedTime < 1.0f) {
// Calculating the new bottom margin, and setting it
mViewLayoutParams.rightMargin = mMarginStart
+ (int) ((mMarginEnd - mMarginStart) * interpolatedTime);
// Invalidating the layout, making us seeing the changes we made
mAnimatedView.requestLayout();
// Making sure we didn't run the ending before (it happens!)
} else if (!mWasEndedAlready) {
mViewLayoutParams.rightMargin = mMarginEnd;
mAnimatedView.requestLayout();
mWasEndedAlready = true;
}
}
}
和我用这个动画:
View parent = (View) v.getParent();
View containerMenu = parent.findViewById(R.id.containerMenu);
ExpandAnimation anim=new ExpandAnimation(containerMenu, 1000);
containerMenu.startAnimation(anim);
这动画切换布局hidding /显示它。
This animation toggle a layout hidding / showing it.
在默认情况下,其隐藏。当我点击,动画作品,它的显示。当我再次点击,它正确地收缩。但第三次,它什么都不做。我已经调试和我发现,调用构造函数的而不是 applyTransformation
。
不知怎么的,如果我点击屏幕上的任何布局,动画突然开始。
By default, its hidden. When I click, animation works and it's shown. When I click again, it shrinks correctly. But the 3rd time, it does nothing. I've debugged and I found out that the constructor is called but not applyTransformation
.
Somehow, if I click any layout around the screen, the animation suddenly starts.
任何想法?
修改
有谁知道什么时候被触发applyTransformation?
Edit Does anyone know WHEN is applyTransformation triggered?
推荐答案
我不明白为什么,但是当我点击或做任何布局的任何行动,动画终于启动。所以我加入编程一种解决方法。我在我的布局中滚动视图,所以我移动滚动的位置是:
I can't understand why, but when I click or do any action to any layout, the animation finally starts. So I programatically added a workaround. I've a scrollview in my layout, so I move the scroll position:
hscv.scrollTo(hscv.getScrollX()+1, hscv.getScrollY()+1);
这刚过 containerMenu.startAnimation(阿尼姆);
这只是工作,我不明白这是为什么。
This just works, I can't understand why.
另外,我发现了一些动画制作的Android> 4无瑕,但在2.3例如,它有同样的问题,努力扩大和缩小,而不是扩大第二次。
Also, I found out that some animations worked flawless on android > 4, but on 2.3 for instance, it had the same issue, worked to expand, and to shrink, but not to expand for the second time.
parent.invalidate();
做的伎俩。
这篇关于动画方法applyTransformation不会触发,直到我点击任何布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!