我想以ImageView为中心。到目前为止我正在使用它:
private void moveViewToScreenCenter(View view, RelativeLayout relativeLayout) {
DisplayMetrics dm = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(dm);
int statusBarOffset = dm.heightPixels - relativeLayout.getMeasuredHeight();
int originalPos[] = new int[2];
view.getLocationOnScreen(originalPos);
int xDest = dm.widthPixels / 2;
xDest -= (view.getMeasuredWidth() / 2);
int yDest = dm.heightPixels / 2 - (view.getMeasuredHeight() / 2) - statusBarOffset;
TranslateAnimation anim = new TranslateAnimation(0, xDest - originalPos[0], 0, yDest - originalPos[1]);
anim.setDuration(1000);
anim.setFillAfter(true);
view.startAnimation(anim);
}
现在,当动画结束时,视图应该转到原点。我怎么能这样做?
答案 0 :(得分:0)
切换这个:
anim.setFillAfter(真);
用这个:
anim.setFillAfter(假);