安卓ontouch问题移动图片
用ontouch移动一张图片为什么图片不和ontouch触摸点在一起啊
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ll=(LinearLayout) findViewById(R.id.ll);
iv=(ImageView) findViewById(R.id.iv);
iv.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_MOVE){
lp=(LayoutParams) iv.getLayoutParams();
lp.leftMargin=(int) event.getRawX();
lp.topMargin=(int) event.getRawY();
iv.setLayoutParams(lp);
}
return true;
[最优解释]
layout.leftMargin = (int) event.getRawX()- iv.getWidth() / 2;
layout.topMargin = (int) event.getRawY()- iv.getHeight() / 2;
[其他解释]
你的坐标算的有问题吧。
[其他解释]
能具体给改下不。我新手
[其他解释]