我正在开发一个应用程序,我想在我的布局上拖动图像视图、触摸事件。但问题是我正在从 Facebook 检索位图图像,而拖动它会自动缩放到较小的图像。
ImageView img = (ImageView)findViewById(R.id.edit_text_image);
Bitmap bm=getFacebookImage();
img.setImageBitmap(bm);
img.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Toast.makeText(MoveImage.this,"hiii", Toast.LENGTH_SHORT).show();
switch(event.getAction())
{
// case MotionEvent.ACTION_DOWN:
//
// break;
case MotionEvent.ACTION_MOVE:
//Toast.makeText(MoveImage.this,"moved", Toast.LENGTH_SHORT).show();
ImageView img=(ImageView)findViewById(v.getId());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(img.getLayoutParams());
//
int x_cord = (int)event.getRawX();
int y_cord = (int)event.getRawY();
if(x_cord>windowwidth){x_cord=windowwidth;}
if(y_cord>windowheight){y_cord=windowheight;}
params.leftMargin = x_cord - 25; //(int)event.getX();//
params.topMargin = y_cord - 75; // (int)event.getY();//
img.setLayoutParams(params);
break;
}
return true;
}
});
如果我从资源中获取图像,它工作正常:
ImageView img = (ImageView)findViewById(R.id.edit_text_image);
img.setBackgroundResource(R.drawable.ic_launcher);
// same touch event here