I have a small ImageView inside a full-screen FrameLayout, and I would like to set it so that when I touch FrameLayout, the image will be viewed at this position.
I read all the other questions I can find about moving an ImageView, but I did not see why my solution is still not working.
In a custom view that 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 changed the marker layoutparams to reflect the new position of the touch, and invalidated the image and framemayut (not sure which one I should do), but the imageView does not move (it just sits always in the upper left corner of the frame corner).
I also checked that this method is called when I touch the screen, and the parameters change using normal values โโof X and Y.
My layout:
<CustomFrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/draggedImage" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/pause" /> </CustomFrameLayout>
Edit: I have to mention that I am trying to customize the API level 10, so I can not use any support for cellular advertising orientation :(
source share