移动 ImageView:ScrollBy() 和 ScrollTo()

发布于 2024-12-18 05:46:58 字数 931 浏览 2 评论 0原文

我想以编程方式移动 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>

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. */

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2024-12-25 05:46:58

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文