移动 ImageView:ScrollBy() 和 ScrollTo()
我想以编程方式移动 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 ImageView.setX(float) 和 ImageView.setY(float) 函数。
You should be using the ImageView.setX(float) and ImageView.setY(float) functions.