Android 图像切换器
我正在构建一个 ImageSwitcher 以适合移动应用程序作为横幅切换器。目前,我们使用处理程序旋转横幅并将可运行程序延迟 7 秒(确切地说是 7000 毫秒),但我们希望在两个图像之间有更奇特的过渡效果。我使用这个作为参考,并度过了一段可怕的时光。我理解它背后的概念,但我想完全删除画廊部分,只使用我们必须使用 ImageSwitch 过渡的处理程序。
这是我们的图像切换代码:
private Runnable updateBannerRun = new Runnable(){
public void run() {
if (bannerQueue > 3){
bannerQueue = 1;
} else {
bannerQueue ++;
}
ImageView i = (ImageView)findViewById(R.id.imageView1);
switch (bannerQueue){
case 1:
i.setImageResource(R.drawable.image1);
break;
case 2:
i.setImageResource(R.drawable.image2);
break;
case 3:
i.setImageResource(R.drawable.image3);
break;
case 4:
i.setImageResource(R.drawable.image4);
break;
}
updateBanner();
}
};
这是处理程序的代码:
public void updateBanner(){
mHandler.postDelayed(updateBannerRun, 7000);
}
我最大的问题是当我们运行它时,我们得到一个 nullPointException 返回。
任何帮助将不胜感激。
I'm building an ImageSwitcher to fit in a mobile app as a banner switcher. Currently we have rotating banners using a Handler and delaying a runnable by 7 seconds(7000ms, to be exact), but we want a more fancy transition effect between two images. I'm using this as a reference, and having a horrible time doing so. I understand the concept behind it, but I want to cut the gallery part out entirely and just use the handler we we have to use the ImageSwitch transitions.
This is our code for the image switching:
private Runnable updateBannerRun = new Runnable(){
public void run() {
if (bannerQueue > 3){
bannerQueue = 1;
} else {
bannerQueue ++;
}
ImageView i = (ImageView)findViewById(R.id.imageView1);
switch (bannerQueue){
case 1:
i.setImageResource(R.drawable.image1);
break;
case 2:
i.setImageResource(R.drawable.image2);
break;
case 3:
i.setImageResource(R.drawable.image3);
break;
case 4:
i.setImageResource(R.drawable.image4);
break;
}
updateBanner();
}
};
This is the code for the handler:
public void updateBanner(){
mHandler.postDelayed(updateBannerRun, 7000);
}
My biggest issue is when we run it, we get a nullPointException returned.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少
setFactory()
调用。查看我的博客文章:Android 提示:TextSwitcher 和 ImageSwitcher
You are missing the
setFactory()
call.Check my blog post: Android Tip: TextSwitcher and ImageSwitcher