开发者

Updating the position of an image

Hi I am fairly new to Drawing with Andro开发者_C百科id. I was looking for a simplest way to do the following:

  1. change the position of an image I have placed at a starting x,y location
  2. may layout has background images, etc, I have a frame layout defined with a placeholder in xml.
  3. I have found may questions related to moving images on fling, 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. i.e. translate.image(x,y); most items I find get complex dealing with gestures, animations etc.

I have this basic framelayout in my main xml layout:

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

   >

Thanks


Try something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜