练习:放入三张图片,使其滑动显示,并在最后一张跳转到另一个界面。
布局:
<?xml version="1.0" encoding="utf-8"?>
<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=".ViewPagerActivity">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vp"
android:background="#161616"
>
</android.support.v4.view.ViewPager>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/iv"
android:src="@mipmap/ic_launcher"
android:scaleType="centerCrop"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/tv"
android:gravity="center"
android:text="测试"
/>
</LinearLayout>
单个图片效果:图片在上,文字在下。
如图:
代码:
package com.example.administrator.jreduch05;
<?xml version="1.0" encoding="utf-8"?> <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=".ViewPagerActivity"> <android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/vp" android:background="#161616" > </android.support.v4.view.ViewPager> </RelativeLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/iv" android:src="@mipmap/ic_launcher" android:scaleType="centerCrop" /> <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:id="@+id/tv" android:gravity="center" android:text="测试" />