Android中实现图片自动滚动的效果非常的常见,我们可以自己动画去实现功能。但是在Android中提供了一个ViewPager类,实现了滚动效果,在Android的extras目录下android-support-vx.jar中,x代表版本4,7等等。使用时我们需要android.support.v4.view.ViewPager的viewPager标签。
博客来源:http://blog.csdn.net/fengshizty
代码非常的简单,不用解释:
xml布局文件如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.andy.viewpagedemo.MainActivity" >
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="200dip" />
<LinearLayout
android:layout_alignBottom="@id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#33000000"
android:orientation="vertical" >
<TextView
android:id="@+id/image_desc"