Android 中的自动滑动图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21303912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto Slide image in Android
提问by user3226468
Im trying to write a very basic android app that displays around 5 pictures one after each other on the screen. I want it to display a different picture after about 10 seconds. Can anyone advise me on how I would go around this. Below i have outlined what i would be looking for.
我正在尝试编写一个非常基本的 android 应用程序,它在屏幕上一个接一个地显示大约 5 张图片。我希望它在大约 10 秒后显示不同的图片。任何人都可以建议我如何解决这个问题。下面我概述了我要寻找的东西。
Picture 1
图片1
Picture 2
图2
Picture 3
图3
Picture 4
图4
Picture 5
图5
display full screen Picture 1 wait 10 seconds Remove Picture 1 and Display Picture 2 Wait 10 seconds Remove Picture 2 and Display Picture 3 Wait 10 seconds Remove Picture 3 and Display Picture 4 Wait 10 seconds Remove Picture 4 and Display Picture 5 Wait 10 seconds
显示全屏 图片 1 等待 10 秒 删除图片 1 并显示图片 2 等待 10 秒 删除图片 2 并显示图片 3 等待 10 秒 删除图片 3 并显示图片 4 等待 10 秒 删除图片 4 并显示图片 5 等待 10 秒
Start again...thanks
重新开始……谢谢
回答by user543
You can use viewflipper for this:
您可以为此使用 viewflipper:
view_flipper.xml:
view_flipper.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoStart="true"
android:flipInterval="2000" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture3" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture4" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture5" />
</ViewFlipper>
</RelativeLayout>
Mention this xml file in onCreate of your mainActivity. Like:
在 mainActivity 的 onCreate 中提及此 xml 文件。喜欢:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_flipper);
}
Thats it. After loading layout it will automatically start animating because we mention autoStart:true in xml.
就是这样。加载布局后,它会自动开始动画,因为我们在 xml 中提到了 autoStart:true。
回答by Jigar Pandya
You can use View flipper to slide your images and to do same automatically at some interval,use TimerTask along with View Flipper.
您可以使用 View Flipper 来滑动您的图像并在某个时间间隔自动执行相同的操作,将 TimerTask 与 View Flipper 一起使用。
Inside TimerTask, use Viewflipper.showNext();
在 TimerTask 中,使用 Viewflipper.showNext();
Have a look at this post.
看看这个帖子。
Also have a look at startFlipping() and setFlipInterval() methods in ViewFlipper class
还可以查看 ViewFlipper 类中的 startFlipping() 和 setFlipInterval() 方法
http://android-er.blogspot.com/2011/03/auto-flipping-of-viewflipper.html
http://android-er.blogspot.com/2011/03/auto-flipping-of-viewflipper.html
http://javatechig.com/android/android-viewflipper-example
http://javatechig.com/android/android-viewflipper-example
You can ask if you have any further queries..
有什么问题可以问。。