ビューの位置の値を取得する方法は複数あります。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)、と私はTranslateAnimationで使用される値を反映doen't .. 。
アイデア?
ありがとうございました。 – Quv