先来看看ViewPager使用到的场景,是十分的普遍
比如第一次进入程序闪屏页上的应用:
标题栏:
以及类似网易新闻上带图片带内容的一个ViewPager
我们来实现这样的效果,话不多说,看代码,注释
红点和白点的代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<corners android:radius="5dp"/>
<solid android:color="@android:color/white"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<corners android:radius="5dp"/>
<solid android:color="#ff0000"/>
</shape>
布局文件,在几个小点不能写死,所以我们在代码再来生成几个小点
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="180dp"></android.support.v4.view.ViewPager>
<LinearLayout
android:layout_width=