Android - dynamically changing image position

I am currently using the matrix method to implement drag and drop for the image (image A)

Now I want part of image A to be clicked, so I put another image (image B) on top of image A and set layout_margins for it in the xml file.

My question is: is there a way to dynamically change my mangan layouts since I am scaling my image to enlarge and scale the image?

I think a simpler question is: how do I dynamically set layout_margins for an image?

<RelativeLayout
  xmlns:android="http://schemas.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>

thank!

+5
source share
2 answers

. "android.widget.FrameLayout.LayoutParams" .

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);
+4
0

All Articles