Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving ImageView: ScrollBy() and ScrollTo()

I want to programmatically move ImageView (change its position in the axes x and y). Code in main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <com.app.name.GameView
        android:id="@+id/game"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

</FrameLayout>

Code in Activity:

ImageView image = (ImageView) findViewById(R.id.image);
image.setBackgroundResource(R.anim.my_anim);

image.scrollTo (10,10);

/* Creating animation... */

mAnim = (AnimationDrawable) image.getBackground();
/* etc. */

Commands ScrollBy() and ScrollTo() don’t work. May don’t need to move image, but mAnim?

like image 315
bosiakov Avatar asked May 01 '26 18:05

bosiakov


1 Answers

You should be using the ImageView.setX(float) and ImageView.setY(float) functions.

like image 152
MrZander Avatar answered May 03 '26 09:05

MrZander