android TranslateAnimation动画焦点跟随问题

时间:2022-11-17 22:04:59

给一个activity设置移动动画,移动后,焦点并没有跟随,实现焦点跟随的效果,可以这样设置:

 mainlayout = (RelativeLayout) findViewById(R.id.main_activity);
final Animation animation = new TranslateAnimation(0, -100, 0, 0);
animation.setDuration(50);

animation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}
// 这里就是实现焦点跟随
@Override
public void onAnimationEnd(Animation animation) {
mainlayout.clearAnimation();
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getWh().x, getWh().y);
lp.setMargins(-100, 0, getWh().x + 100, getWh().y);//getwh()自定义的一个获取宽和高的方法
mainlayout.setLayoutParams(lp);
}