Image Position Update

Hi, I'm pretty new to drawing with Android. I was looking for the easiest way to do the following:

  • reposition the image that I placed at the original location x, y
  • Can a layout have background images, etc. I have a frame layout defined using placeholder in xml.
  • I found issues related to moving images when dragging or dragging.

I just need a basic setup where my code generates a value for x, y, and then I just translate the image to its new location with these x, y values. those. translate.image (x, y); most of the items that I find are complex in terms of gestures, animations, etc.

I have this basic frame in my main xml layout:

<FrameLayout  
   android:id="@+id/graphics_holder"  
   android:layout_height="170px"  
   android:layout_width="match_parent"

   >

thank

+3
source
1

- :

FrameLayout myView = (FrameLayout) findViewById(R.id.graphics_holder);  

int toX = 50; // change these
int toY = 100;
LayoutParams lp = (LayoutParams) myView.getLayoutParams();
lp.leftMargin = toX;
lp.topMargin = toY;
myView.setLayoutParams(lp);
myView.layout(toX, toY, 0, 0); // might be unnecessary
0

Source: https://habr.com/ru/post/1796616/


All Articles