亲爱的, 我是移动android平台的新手。我有5个图像序列视图如何动画这些图像。即第一应该是可见的休息应该是看不见的。比第二个应该是可见的休息应该是隐形的,因为它必须反复做...我该怎么办...我正在使用相对布局...帮助表示赞赏....
答案 0 :(得分:0)
也许你应该使用GalleryView。 Example
答案 1 :(得分:0)
如果您想要的是切换不同的图像(这是我解释您的问题的方式),请查看ImageSwitcher
或者您可以手动执行此操作,方法是通过运行Thread或Timer来切换ImageView的图像资源以获得更多便利,但我相信上面的链接对您来说更容易
答案 2 :(得分:0)
据我所知,如果您希望所有图像都在同一图像视图中,则需要使用AnimationDrawable
如果您希望每个图像以不同的ImageView显示,那么您可以实现Runnable及其run方法set imageview1.setImage(null);和imageview2.setImage(你想要的),并根据你想要的每次更改你设置的ImageView
在run方法结束时,您应该使用handler.postAtTime()方法在下次需要时再次启动runnable。
注意:Handler是在您的活动中创建的,并传递给构造函数中的runnable或您想要的任何内容
我希望这很清楚。如果没有,请告诉我。
EDIT1
要制作几个imageView动画,那么你应该按照以下方式实现Runnable
import android.app.Activity;
import android.os.Handler;
import android.os.SystemClock;
import android.widget.ImageView;
public class Animator implements Runnable {
// handler to register the runnable
private Handler handler;
private Activity activity;
// to know the current imageView that we will assign the current image to
private int next_image_view;
public Animator(Handler handler, Activity activity) {
this.handler = handler;
this.activity = activity;
next_image_view = 0;
}
@Override
public void run() {
ImageView first = null;
ImageView second = null;
switch (next_image_view) {
case 0:
first = (ImageView) activity.findViewById(R.id.imageView1);
second = (ImageView) activity.findViewById(R.id.imageView2);
break;
case 1:
first = (ImageView) activity.findViewById(R.id.imageView2);
second = (ImageView) activity.findViewById(R.id.imageView3);
break;
case 2:
first = (ImageView) activity.findViewById(R.id.imageView3);
second = (ImageView) activity.findViewById(R.id.imageView4);
break;
case 3:
first = (ImageView) activity.findViewById(R.id.imageView4);
second = (ImageView) activity.findViewById(R.id.imageView5);
break;
case 4:
first = (ImageView) activity.findViewById(R.id.imageView5);
second = (ImageView) activity.findViewById(R.id.imageView6);
break;
case 5:
first = (ImageView) activity.findViewById(R.id.imageView6);
second = (ImageView) activity.findViewById(R.id.imageView1);
break;
default:
break;
}
if (first != null && second != null) {
first.setBackgroundResource(0);
second.setBackgroundResource(R.drawable.icon);
}
next_image_view++;
if (next_image_view == 6) {
// to start from the beginning again
next_image_view = 0;
}
// here we post this runnable to be running again after 1 sec = 1000 MS
handler.postAtTime(this, SystemClock.uptimeMillis() + 1000);
}
}
和TestActivity如下
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.widget.ImageView;
public class TestActivity extends Activity{
private Animator animator;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.animation_layout);
ImageView view = (ImageView) findViewById(R.id.imageView1);
view.setBackgroundResource(R.drawable.icon);
handler = new Handler();
animator = new Animator(handler, this);
handler.postAtTime(animator, SystemClock.uptimeMillis() + 1000);
}
}
您的XML文件应包含6个具有相应名称的imageView。