我有一个从 Internet 收集的示例。
public class MprojectActivity extends Activity {
/** Called when the activity is first created. */
ImageView itan2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
itan2=(ImageView)findViewById(R.id.imageView18);
itan2.setOnTouchListener( new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction()==MotionEvent.ACTION_MOVE){
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) itan2.getLayoutParams();
int x =(int) event.getRawX();
int y =(int) event.getRawY();
mParams.leftMargin = x-236;
mParams.topMargin = y-565;
itan2.setLayoutParams(mParams);
}
return true;
}
});
}
}
在这个例子中,我用 x 和 y 减去 236 和 565。这些值实际上是什么。如何通过动态编码找到它们?