移动ImageView:ScrollBy()和ScrollTo()

时间:2011-11-28 19:13:16

标签: android imageview move

我想以编程方式移动ImageView(更改其在x和y轴上的位置)。 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>

活动代码:

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

image.scrollTo (10,10);

/* Creating animation... */

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

命令ScrollBy()和ScrollTo()不起作用。可能不需要移动图像,但是mAnim?

1 个答案:

答案 0 :(得分:5)

您应该使用 ImageView.setX(浮动) ImageView.setY(浮动)函数。

相关问题