用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;
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.topMargin = (int) event.getRawY()- iv.getHeight() / 2;