简体   繁体   中英

How do I move an ImageView in AbsoluteLayout to X Y position

my main.xml look like this:

<AbsoluteLayout
   android:id="@+id/AbsoluteLayout01"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   xmlns:android="http://schemas.android.com/apk/res/android"> 

   <ImageView
      android:layout_height="wrap_content"
      android:layout_x="247dip"
      android:layout_width="wrap_content"
      android:layout_y="96dip"
      android:id="@+id/Ball"
      android:src="@drawable/ball"/>

</AbsoluteLayout>

And Java

ball = (ImageView) findViewById(R.id.Ball);

How do I do if I whant to move the ball from x=247dip, y=96dip to x=100, y=100 while my app is running?

First set Image's Layout Height and width to Fillparent then use below code

public void onWindowFocusChanged(boolean hasFocus) {

        ball.scrollTo(10, 20);
    }
ball.setLeft(10); //this moves view 10 pixel to left
ball.setLeft(-10); //this moves view 10 pixel to right
ball.setRight(10);//this moves view 10 pixel to right

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM