我知道多种方式来获取视图的位置值。Android:有没有办法在TranslateAnimation之后获得View的最新位置?
getLocationOnScreen()
getLocationInWindow()
getLeft()
然而,他们没有实际返回我感动的startAnimation()方法查看当前位置,但只有原来的位置。因此,现在让我们制作一个视图,在每次点击时向右移动10个像素(我省略了布局,因为您可以将任何视图放在主XML中并将其放在onClickListener上)。
public class AndroidTestActivity extends Activity implements OnClickListener {
LinearLayout testView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testView = (LinearLayout) this.findViewById(R.id.test);
testView.setOnClickListener(this);
}
public void onClick(View v) {
int[] pLoS = new int[2];
testView.getLocationOnScreen(pLoS);
TranslateAnimation move = new TranslateAnimation(pLoS[0], pLoS[0] + 10, 0f, 0f);
move.setFillAfter(true);
move.setFillEnabled(true);
testView.startAnimation(move);
}
}
正如你看到的,因为我打算,因为getLocationOnScreen这不起作用()总是返回相同的值(在我的情况,0),doen't反映我TranslateAnimation使用的值.. 。
有什么想法?
非常感谢。 – Quv