0
ImageView currentImage = (ImageView) findViewById(R.id.image) ;  
onTouch(View v, MotionEvent event){
 if(event.getAction() == MotionEvent.ACTION_DOWN){
    float x = event.getX() ;
    float y = event.getY();
    currentImage.setX(x) ;
    currentImage.setY(y) ;
    //the 2 lines above must be dragging the image across the screen
 }


 if( event.getAction() == MotionEvent.ACTION_UP){
     currentImage.setX(x) ;
     currentImage.setY(y) ;
 }

}

However, the code does not work, this is the closest i could come up with.

ERJAN
  • 23,696
  • 23
  • 72
  • 146

1 Answers1

1

For anything below Honeycomb (API Level 11) you will have to use setLayoutParams():-

If superLayout is RelativeLayout-

 RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(int width, int height);
    layoutParams.setMargins(int left, int top, int right, int bottom);
    imageView.setLayoutParams(layoutParams);

If superLayout is Linearlayout-

 Linearlayout.LayoutParams layoutParams=new Linearlayout.LayoutParams(int width, int height);
    layoutParams.setMargins(int left, int top, int right, int bottom);
    imageView.setLayoutParams(layoutParams);

And If you limit your support to Honeycomb and up you can use the setX(), setY(), setLeft(), setTop()

NehaK
  • 2,639
  • 1
  • 15
  • 31
  • i m using api22 - the latest, why would I think about something below api 11? can you give more relevant advice? – ERJAN Jun 17 '15 at 12:10