我正在通过此代码移动视图,但是视图的实际位置未更改,为什么
TranslateAnimation ta = new TranslateAnimation(0, 0, Animation.RELATIVE_TO_SELF, -mbar4.getHeight());
ta.setDuration(1000);
ta.setFillAfter(true);
v4.startAnimation(ta);
解决方法:
在不包括android版本3(API 11)的情况下,所有动画都不会真正改变视图,而只会改变其显示方式.不仅如此,但我认为他们根本不使用GPU.
为了将其检出,可以使用按钮和setOnClickListener,并看到无论使用哪种动画,单击仅在其原始位置和大小上起作用.
这是使用translateAnimation移动视图的示例代码:
final int deltaXToMove=50;
TranslateAnimation translateAnimation=new TranslateAnimation(0,deltaXToMove,0,0);
int animationTime=1000;
translateAnimation.setDuration(animationTime);
translateAnimation.setFillEnabled(true);
translateAnimation.setFillAfter(true);
final Button b=(Button)findViewById(R.id.button);
translateAnimation.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
animation.setFillAfter(false);
FrameLayout.LayoutParams par=(LayoutParams)b.getLayoutParams();
par.leftMargin=deltaXToMove;
b.setLayoutParams(par);
}
...
b.startAnimation(translateAnimation);
标签:animation,listview,android
来源: https://codeday.me/bug/20191201/2079245.html