如何使用 imageView 创建幻灯片?
public class AndroidAnim extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView imageView1 = (ImageView) findViewById(R.id.ImageView1);
final ImageView imageView2 = (ImageView) findViewById(R.id.ImageView2);
final AnimationDrawable myAnimation1;
imageView1.setBackgroundResource(R.drawable.loadinganim);
imageView2.setBackgroundResource(R.drawable.loadinganim);
myAnimation1 = (AnimationDrawable) imageView1.getBackground();
imageView2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myAnimation1.start();
imageView2.startAnimation(AnimationUtils.loadAnimation(getBaseContext(), R.anim.effect_in));
}
});
}
}
我是安卓新手。我需要一些帮助。我使用这段代码尝试创建幻灯片,我想要一张又一张地循环图像,当然还有效果(本例中的effect-in.xml)。我想向下移动 imageView1,然后向下移动 imageView2,然后向下移动 imageView1,依此类推。我应该在这里做什么,以便我得到结果,对不起我的英语。
public class AndroidAnim extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView imageView1 = (ImageView) findViewById(R.id.ImageView1);
final ImageView imageView2 = (ImageView) findViewById(R.id.ImageView2);
final AnimationDrawable myAnimation1;
imageView1.setBackgroundResource(R.drawable.loadinganim);
imageView2.setBackgroundResource(R.drawable.loadinganim);
myAnimation1 = (AnimationDrawable) imageView1.getBackground();
imageView2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myAnimation1.start();
imageView2.startAnimation(AnimationUtils.loadAnimation(getBaseContext(), R.anim.effect_in));
}
});
}
}
I am new in android. I need some help. I use this code trying to create slideShow, I want loop images one after another, of course with effect (effect-in.xml in this example). I want to move down imageView1 and after that should move down imageView2, and after that imageView1 and so on. What should I do here, so I get the result, sorry for my english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 android ViewFlipper,它允许为不同的视图指定进出动画,并且它一次只会显示 1 个视图。你把它设置为自动翻转。
但是,如果您正在寻找一组图像的连续滑块这个项目可能是一些参考。
You can use the android ViewFlipper which allows to specify a in and out animation for the different views and it will only show 1 view at a time. You set it to flip automatically.
But if you are looking for a continuous slider of a group of images this project might be some reference.