工程:https://github.com/LillteZheng/ViewPagerHelper
APP 啓動引導頁
正常版 | 移動版 | 縮放版 |
---|---|---|
使用
如果你要使用 引導頁,也是非常簡單,只需要使用 GlideViewPager 即可。配置與上面基本一致:
佈局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:zsr="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:clipToPadding="false"
android:orientation="vertical">
<com.zhengsr.viewpagerlib.view.GlideViewPager
android:id="@+id/splase_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="@+id/splase_start_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:layout_marginBottom="50dp"
android:background="@drawable/glide_bottom_btn_bg"
android:textColor="@color/white"
android:text="@string/start"
android:textSize="18sp"
android:visibility="gone"
/>
<com.zhengsr.viewpagerlib.indicator.TransIndicator
android:id="@+id/splase_bottom_layout"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="50dp"
zsr:trans_leftmargin="10dp"
zsr:trans_movecolor="@color/colorAccent"
zsr:trans_defaultcolor="@color/gray_cccc"
zsr:trans_type="circle"
zsr:trans_width="5dp"
zsr:trans_height="5dp"
zsr:trans_dismiss_open="true"
android:orientation="horizontal"/>
</RelativeLayout>
Button 爲啓動按鈕,這個自行設計即可。
初始化
public void initView() {
GlideViewPager viewPager = (GlideViewPager) findViewById(R.id.splase_viewpager);
TransIndicator linearLayout = (TransIndicator) findViewById(R.id.splase_bottom_layout);
//點擊跳轉的按鈕
Button button = (Button) findViewById(R.id.splase_start_btn);
//先把本地的圖片 id 裝進 list 容器中
List<Integer> images = new ArrayList<>();
for (int i = 0; i < RES.length; i++) {
images.add(RES[i]);
}
//配置pagerbean,這裏主要是爲了viewpager的指示器的作用,注意記得寫上泛型
PageBean bean = new PageBean.Builder<Integer>()
.data(images)
.indicator(linearLayout)
.openView(button)
.builder();
// 把數據添加到 viewpager中,並把view提供出來,這樣除了方便調試,也不會出現一個view,多個
// parent的問題,這裏在輪播圖比較明顯
viewPager.setPageListener(bean, R.layout.image_layout, new PageHelperListener() {
@Override
public void getItemView(View view, Object data) {
ImageView imageView = view.findViewById(R.id.icon);
imageView.setImageResource((Integer) data);
}
});
//點擊實現跳轉功能
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(GlideTransActivity.this,MainActivity.class));
Toast.makeText(GlideTransActivity.this, "回到首頁", Toast.LENGTH_SHORT).show();
finish();
}
});
}
代碼幫助
可以通過代碼去查看怎麼配置