我尝试在方法ViewHelper.setPivotY(test, 0);
中设置onClick()
,但它不起作用。动画仍然缩放到centerY。这是我的代码。我不知道我哪里错了?
公共类NewClassTest扩展了Activity {
LinearLayout test;
FrameLayout content;
Button btn;
boolean toggle = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
test = (LinearLayout) findViewById(R.id.test);
content = (FrameLayout) findViewById(R.id.content);
content.setVisibility(View.INVISIBLE);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// ViewHelper.setPivotY(test, 0); does not work
runAnimation(toggle);
toggle = !toggle;
}
});
ViewHelper.setPivotY(test, 0); // work
}
private void runAnimation(boolean in){
AnimatorSet animSet = new AnimatorSet();
ObjectAnimator anim = null, anim2 = null;
// ViewHelper.setPivotY(test, 0); also does not work
if(in){
anim = ObjectAnimator.ofFloat(test, "scaleY", 1, 1 - (((float)content.getHeight()) / ((float) test.getHeight())));
anim2 = ObjectAnimator.ofFloat(content, "translationY", content.getHeight(), 0);
animSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
content.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
}else {
anim = ObjectAnimator.ofFloat(test, "scaleY", 1 - ((float)content.getHeight()) / ((float) test.getHeight()), 1);
anim2 = ObjectAnimator.ofFloat(content, "translationY", 0, content.getHeight());
animSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
content.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
}
animSet.setDuration(1000).play(anim2).with(anim);
animSet.start();
}
感谢您的帮助!
答案 0 :(得分:1)
也发生在我身上。使用android 4.1在HTC One S上进行测试并且它没有用,但在三星Galaxy I和Android 2.2中它按预期工作。
将其更改为ViewHelper.setPivotY(test, 0.00000001f);
解决了它= \
不知道它是否是HTC,android或nineoldandroids的错误