I've got a small ImageView inside of a fullscreen FrameLayout, and I'd like to set it such that when I touch the FrameLayout, the imageview moves to that position.
I've read all the other SO questions I can find about moving ImageView but I haven't seen why my solution is not working yet.
In a custom view which extends FrameLayout:
@Override
public boolean onInterceptTouchEvent(MotionEvent event){
if(event.getActionMasked() == MotionEvent.ACTION_DOWN){
ImageView iv = (ImageView) this.findViewById(R.id.draggedImage);
FrameLayout.LayoutParams params = (LayoutParams) iv.getLayoutParams();
params.leftMargin = (int) event.getX();
params.bottomMargin = (int) event.getY();
iv.setLayoutParams(params);
iv.invalidate();
invalidate();
}
return true;
}
I've changed the layoutparams margin to reflect the new touch position, and invalidated the imageview and framelayout (not sure which of these I should be doing), but the imageView doesn't budge (just sits always in the top left corner of the frame).
I've also verified that this method is being called when I touch the screen and the params is getting set with sane X and Y values.
My layout:
<CustomFrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- some other unrelated views -->
<ImageView
android:id="@+id/draggedImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/pause" />
</CustomFrameLayout>
Edit: Should have mentioned that I'm trying to target API level 10, so I can't use any of the Honeycomb view orientation goodness :(