Reputation: 469
:) I'm adding an ImageView inside a WebView like this :
void addImv(int in)
{
imageView.setId(imageID);
webComp.addView(imageView);
Bitmap bitmap;
File sd = Environment.getExternalStorageDirectory();
if(sd.canRead()){
bitmap = BitmapFactory.decodeFile(sd.getAbsolutePath() + "/FMS/1/file"+in+".jpg");
imageView.setImageBitmap(bitmap);
imageView.setAdjustViewBounds(true);
imageView.setMaxHeight(150);
imageView.setAlpha(150);
imageView.bringToFront();
}
}
The photo is shown in the left top of the screen correctly. Now I have this listener for touches on the imageView
OnTouchListener listenTouch = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
};
which works too. How can i set the position of the imageView? I've tried using imageView.setPadding and imageView.imageView.setLayoutParams but clearly I'm doing something really wrong as it force-closes. The imageView isn't defined in xml layout file. Thank you!
Upvotes: 2
Views: 3657
Reputation: 469
This worked:
OnTouchListener listenTouch = new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
imageView.offsetLeftAndRight((int)event.getX()-imageView.getWidth());
imageView.offsetTopAndBottom((int)event.getY()-imageView.getHeight());
webComp.invalidate();
return true;
}
};
Upvotes: 1
Reputation: 25536
Use AbsoluteLayout.LayoutParams setting the correct X and Y co-ordinate or you can also use LinearLayout.LayoutParams OR RelativeLayout.LayoutParams for the purpose.
On how to use:
webComp.addView(imageView, <your params object>);
Upvotes: 0