diff --git a/README.md b/README.md index 79c3d209..d4d6c68b 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ [![JitPack](https://jitpack.io/v/zhpanvip/BannerViewPager.svg)](https://jitpack.io/#zhpanvip/BannerViewPager) [ ![JCenter](https://api.bintray.com/packages/zhpanvip/CircleViewPager/bannerview/images/download.svg) ](https://bintray.com/zhpanvip/CircleViewPager/bannerview/_latestVersion) + +> 腾讯视频、QQ音乐、酷狗音乐、支付宝、天猫、淘宝、优酷视频、喜马拉雅、网易云音乐、哔哩哔哩、全民K歌等App的Banner样式都可以通过BannerViewPager实现哦! + + ## 效果预览 ### [点击或扫描二维码下载apk](https://github.com/zhpanvip/BannerViewPager/raw/master/download/app.apk) @@ -384,14 +388,19 @@ public class FigureIndicatorView extends BaseIndicatorView { - [x] 目前Indicator部分代码比较乱,还有很大很大的优化空间,后续版本将持续优化(2.5.0对Indicator再次进行了重构,重构后代码已经很整洁,但仍然有优化空间) - [ ] ViewPager更换为ViewPager2 (3.0.0) - + +## 有问题可以扫码加QQ群交流 + + ![QQ交流群60902509](https://github.com/zhpanvip/BannerViewPager/blob/master/image/qq_group.png) ## 更多详情请参看以下链接 [《打造一个丝滑般自动轮播无限循环Android库》](https://juejin.im/post/5d6bce24f265da03db0790d1) + [《BannerViewPager源码解析》](https://juejin.im/post/5d74d3faf265da03b5747015) +[《剖析BannerViewPager中Indicator的设计思想》](https://juejin.im/post/5dda0b6d518825731f569a8c) ## 感谢 diff --git a/app/src/main/java/com/example/zhpan/circleviewpager/activity/WelcomeActivity.kt b/app/src/main/java/com/example/zhpan/circleviewpager/activity/WelcomeActivity.kt index 7564e5bf..b5ae616d 100644 --- a/app/src/main/java/com/example/zhpan/circleviewpager/activity/WelcomeActivity.kt +++ b/app/src/main/java/com/example/zhpan/circleviewpager/activity/WelcomeActivity.kt @@ -15,7 +15,6 @@ import com.example.zhpan.circleviewpager.viewholder.CustomPageViewHolder import com.zhpan.bannerview.BannerViewPager import com.zhpan.bannerview.adapter.OnPageChangeListenerAdapter import com.zhpan.bannerview.constants.IndicatorSlideMode -import com.zhpan.bannerview.constants.IndicatorStyle import com.zhpan.bannerview.constants.TransformerStyle import com.zhpan.bannerview.holder.HolderCreator import com.zhpan.bannerview.utils.BannerUtils diff --git a/app/src/main/java/com/example/zhpan/circleviewpager/fragment/BaseFragment.kt b/app/src/main/java/com/example/zhpan/circleviewpager/fragment/BaseFragment.kt index 9a939144..fa690a96 100644 --- a/app/src/main/java/com/example/zhpan/circleviewpager/fragment/BaseFragment.kt +++ b/app/src/main/java/com/example/zhpan/circleviewpager/fragment/BaseFragment.kt @@ -34,14 +34,15 @@ abstract class BaseFragment : RxFragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(layout, container, false) - initData() + initData(3) initTitle() initView(savedInstanceState, view) return view } - private fun initData() { - for (i in 0..3) { + protected fun initData(j: Int) { + mDrawableList.clear() + for (i in 0..j) { val drawable = resources.getIdentifier("t$i", "drawable", mContext.packageName) mDrawableList.add(drawable) } diff --git a/app/src/main/java/com/example/zhpan/circleviewpager/fragment/PageFragment.java b/app/src/main/java/com/example/zhpan/circleviewpager/fragment/PageFragment.java index b8d673f5..27837ca5 100644 --- a/app/src/main/java/com/example/zhpan/circleviewpager/fragment/PageFragment.java +++ b/app/src/main/java/com/example/zhpan/circleviewpager/fragment/PageFragment.java @@ -1,15 +1,10 @@ package com.example.zhpan.circleviewpager.fragment; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.RadioButton; import android.widget.RadioGroup; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import com.example.zhpan.circleviewpager.R; import com.example.zhpan.circleviewpager.viewholder.ImageResourceViewHolder; import com.zhpan.bannerview.BannerViewPager; @@ -19,6 +14,8 @@ import com.zhpan.bannerview.utils.BannerUtils; import com.zhpan.idea.utils.ToastUtils; +import java.util.Random; + /** * Created by zhpan on 2018/7/24. */ @@ -53,6 +50,15 @@ protected void initView(Bundle savedInstanceState, View view) { .setOnPageClickListener(position -> ToastUtils.show("position:" + position)) .setInterval(5000); initRadioGroup(); + + view.findViewById(R.id.btn_refresh).setOnClickListener(v -> updateData()); + } + + private void updateData() { + // 生成[-1,3]整数 + initData(new Random().nextInt(5) - 1); + ToastUtils.show("size=" + getMDrawableList().size()); + mViewPager.create(getMDrawableList()); } public static PageFragment getInstance() { @@ -84,6 +90,10 @@ private void initRadioGroup() { // mViewPager.resetIndicator(); setupOverlapBanner(); break; + case R.id.rb_multi_page_wy: + indicatorView.setVisibility(View.INVISIBLE); + setNetEaseMusicStyle(); + break; } }); radioButton.performClick(); @@ -96,4 +106,16 @@ private void setupOverlapBanner() { .setIndicatorView(indicatorView) .create(getMDrawableList()); } + + // 网易云音乐、QQ音乐类似的Banner都可以通过设置不同的pargeMargin和revealWidth来实现 + private void setNetEaseMusicStyle() { + mViewPager + .setPageMargin(BannerUtils.dp2px(30)) + .setRevealWidth(BannerUtils.dp2px(-15)) + .setPageStyle(PageStyle.MULTI_PAGE) + .setHolderCreator(() -> new ImageResourceViewHolder(BannerUtils.dp2px(5))) + .setIndicatorColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color)) + .setOnPageClickListener(position -> ToastUtils.show("position:" + position)) + .setInterval(5000).create(getMDrawableList()); + } } diff --git a/app/src/main/res/layout/activity_custom_indicator.xml b/app/src/main/res/layout/activity_custom_indicator.xml deleted file mode 100644 index 16b4fc0f..00000000 --- a/app/src/main/res/layout/activity_custom_indicator.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_indicator_slide_mode.xml b/app/src/main/res/layout/activity_indicator_slide_mode.xml deleted file mode 100644 index e6c52801..00000000 --- a/app/src/main/res/layout/activity_indicator_slide_mode.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_page_style.xml b/app/src/main/res/layout/activity_page_style.xml deleted file mode 100644 index 0a6f4b33..00000000 --- a/app/src/main/res/layout/activity_page_style.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_find.xml b/app/src/main/res/layout/fragment_find.xml index dbf64ee1..12de843e 100644 --- a/app/src/main/res/layout/fragment_find.xml +++ b/app/src/main/res/layout/fragment_find.xml @@ -24,9 +24,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/indicator_view" + android:layout_marginStart="10dp" android:text="@string/text_page_style" android:textColor="#000000" - android:layout_marginStart="10dp" android:textSize="18sp" android:textStyle="bold" /> @@ -58,6 +58,21 @@ android:layout_marginTop="15dp" android:text="MULTI_PAGE_OVERLAP" /> + + +