android - dynamically changing the position of an imageview
i'm currently using the matrix method to implement drag and pinch zoom for an image (image A)
Now i want a part of image A to be clickable so i put another imageview (image B) over image A and set the layout_margins for it in the xml file.
My question is...is there a way to dynamically change my layout_margins as i'm scaling my image for drag and pinch zoom?
I guess the simpler question is...how do i dynamically set the layout_margins for an imageview?
<RelativeLayout
xmlns:android="http://sch开发者_C百科emas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/map"
android:scaleType="matrix" />
<ImageView
android:id="@+id/dundas_station"
android:layout_width="75px"
android:layout_height="75px"
android:layout_marginTop="337px"
android:layout_marginLeft="373px"
android:clickable="true"
android:src="@drawable/google_maps_icon"
android:scaleType="matrix"
/>
</RelativeLayout>
thanks!
Use following code snippet. Don forget to import "android.widget.FrameLayout.LayoutParams" or marginal layout params.
ImageView image;
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(100,0, 0,0);
// OR
params.topMargin= 100;
image.setLayoutParams(params);
You use setMargins
精彩评论