Explorar el Código

Update sample for issue #210

zhpanvip hace 3 años
padre
commit
2d0577b8d7

+ 4 - 3
app/build.gradle

@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 apply plugin: 'kotlin-android-extensions'
 android {
-    compileSdkVersion 28
+    compileSdkVersion 30
     buildToolsVersion '28.0.3'
     defaultConfig {
         applicationId "com.example.zhpan.bannerviewpager"
         minSdkVersion 21
-        targetSdkVersion 28
+        targetSdkVersion 30
         versionCode 1
-        versionName "3.5.0"
+        versionName "3.5.2"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
     buildTypes {
@@ -35,6 +35,7 @@ android {
         enabled = true
     }
     dataBinding {
+        //noinspection DataBindingWithoutKapt
         enabled = true
     }
 }

+ 5 - 3
app/proguard-rules.pro

@@ -26,8 +26,10 @@
 -keep class com.example.zhpan.banner.bean.** { *; }
 -keep class com.example.zhpan.banner.net.** { *; }
 -keep class com.zhpan.idea.** { *; }
+-dontwarn com.tencent.bugly.**
+-keep public class com.tencent.bugly.**{*;}
+
 
+# For BannerViewPager
 -keep class androidx.recyclerview.widget.**{*;}
--keep class androidx.viewpager2.widget.**{*;}
--dontwarn com.tencent.bugly.**
--keep public class com.tencent.bugly.**{*;}
+-keep class androidx.viewpager2.widget.**{*;}

BIN
app/release/key


+ 102 - 95
app/src/main/java/com/example/zhpan/banner/activity/WelcomeActivity.kt

@@ -21,111 +21,118 @@ import java.util.*
 
 class WelcomeActivity : BaseDataActivity() {
 
-  private lateinit var mViewPager: BannerViewPager<CustomBean>
+    private lateinit var mViewPager: BannerViewPager<CustomBean>
 
-  private val des = arrayOf("在这里\n你可以听到周围人的心声", "在这里\nTA会在下一秒遇见你", "在这里\n不再错过可以改变你一生的人")
+    private val des = arrayOf("在这里\n你可以听到周围人的心声", "在这里\nTA会在下一秒遇见你", "在这里\n不再错过可以改变你一生的人")
 
-  private val transforms = intArrayOf(
-      TransformerStyle.NONE, TransformerStyle.ACCORDION, TransformerStyle.DEPTH,
-      TransformerStyle.ROTATE, TransformerStyle.SCALE_IN
-  )
+    private val transforms = intArrayOf(
+        TransformerStyle.NONE,
+        TransformerStyle.ACCORDION,
+        TransformerStyle.DEPTH,
+        TransformerStyle.DEPTH_SCALE,
+        TransformerStyle.ROTATE,
+        TransformerStyle.SCALE_IN,
+        TransformerStyle.ROTATE_UP
+    )
 
-  private val data: List<CustomBean>
-    get() {
-      val list = ArrayList<CustomBean>()
-      for (i in mDrawableList.indices) {
-        val customBean = CustomBean()
-        customBean.imageRes = mDrawableList[i]
-        customBean.imageDescription = des[i]
-        list.add(customBean)
-      }
-      return list
-    }
+    private val data: List<CustomBean>
+        get() {
+            val list = ArrayList<CustomBean>()
+            for (i in mDrawableList.indices) {
+                val customBean = CustomBean()
+                customBean.imageRes = mDrawableList[i]
+                customBean.imageDescription = des[i]
+                list.add(customBean)
+            }
+            return list
+        }
 
-  override fun onCreate(savedInstanceState: Bundle?) {
-    super.onCreate(savedInstanceState)
-    setContentView(R.layout.activity_welcome)
-    setupViewPager()
-    updateUI(0)
-  }
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.activity_welcome)
+        setupViewPager()
+        updateUI(0)
+    }
 
-  private fun setupViewPager() {
-    mViewPager = findViewById(R.id.viewpager)
-    mViewPager.apply {
-      setCanLoop(false)
-      setPageTransformer(
-          PageTransformerFactory.createPageTransformer(transforms[Random().nextInt(5)])
-      )
-      setIndicatorMargin(
-          0, 0, 0, resources.getDimension(R.dimen.dp_100)
-          .toInt()
-      )
-      setIndicatorSliderGap(
-          resources.getDimension(R.dimen.dp_10)
-              .toInt()
-      )
-      setIndicatorSlideMode(IndicatorSlideMode.SMOOTH)
-      setIndicatorSliderRadius(
-          resources.getDimension(R.dimen.dp_3)
-              .toInt(), resources.getDimension(R.dimen.dp_4_5)
-          .toInt()
-      )
-      registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
-        override fun onPageSelected(position: Int) {
-          BannerUtils.log("position:$position")
-          updateUI(position)
+    private fun setupViewPager() {
+        mViewPager = findViewById(R.id.viewpager)
+        mViewPager.apply {
+            setCanLoop(false)
+            setPageTransformer(
+                PageTransformerFactory.createPageTransformer(transforms[Random().nextInt(7)])
+            )
+            setIndicatorMargin(
+                0, 0, 0, resources.getDimension(R.dimen.dp_100)
+                    .toInt()
+            )
+            setIndicatorSliderGap(
+                resources.getDimension(R.dimen.dp_10)
+                    .toInt()
+            )
+            setIndicatorSlideMode(IndicatorSlideMode.SMOOTH)
+            setIndicatorSliderRadius(
+                resources.getDimension(R.dimen.dp_3)
+                    .toInt(), resources.getDimension(R.dimen.dp_4_5)
+                    .toInt()
+            )
+            registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
+                override fun onPageSelected(position: Int) {
+                    BannerUtils.log("position:$position")
+                    updateUI(position)
+                }
+            })
+            adapter = SimpleAdapter().apply {
+                mOnSubViewClickListener = object : SimpleAdapter.OnSubViewClickListener {
+                    override fun onViewClick(
+                        view: View?,
+                        position: Int
+                    ) {
+                        ToastUtils.showShort("Logo Clicked,position:$position")
+                    }
+                }
+            }
+            setIndicatorSliderColor(
+                ContextCompat.getColor(this@WelcomeActivity, R.color.white),
+                ContextCompat.getColor(this@WelcomeActivity, R.color.white_alpha_75)
+            )
         }
-      })
-      adapter = SimpleAdapter().apply {
-        mOnSubViewClickListener = object : SimpleAdapter.OnSubViewClickListener {
-          override fun onViewClick(
-            view: View?,
-            position: Int
-          ) {
-            ToastUtils.showShort("Logo Clicked,position:$position")
-          }
-        }
-      }
-      setIndicatorSliderColor(
-          ContextCompat.getColor(this@WelcomeActivity, R.color.white),
-          ContextCompat.getColor(this@WelcomeActivity, R.color.white_alpha_75)
-      )
+            .create(data)
     }
-        .create(data)
-  }
-
-  fun onClick(view: View) {
-    MainActivity.start(this)
-    finish()
-  }
 
-  private fun updateUI(position: Int) {
-    tv_describe?.text = des[position]
-    val translationAnim = ObjectAnimator.ofFloat(tv_describe, "translationX", -120f, 0f)
-    translationAnim.apply {
-      duration = ANIMATION_DURATION.toLong()
-      interpolator = DecelerateInterpolator()
-    }
-    val alphaAnimator = ObjectAnimator.ofFloat(tv_describe, "alpha", 0f, 1f)
-    alphaAnimator.apply {
-      duration = ANIMATION_DURATION.toLong()
+    fun onClick(view: View) {
+        MainActivity.start(this)
+        finish()
     }
-    val animatorSet = AnimatorSet()
-    animatorSet.playTogether(translationAnim, alphaAnimator)
-    animatorSet.start()
 
-    if (position == mViewPager.data.size - 1 && btn_start?.visibility == View.GONE) {
-      btn_start?.visibility = View.VISIBLE
-      ObjectAnimator
-          .ofFloat(btn_start, "alpha", 0f, 1f)
-          .setDuration(ANIMATION_DURATION.toLong())
-          .start()
-    } else {
-      btn_start?.visibility = View.GONE
+    private fun updateUI(position: Int) {
+        tv_describe?.text = des[position]
+        val translationAnim = ObjectAnimator.ofFloat(tv_describe, "translationX", -120f, 0f)
+        translationAnim.apply {
+            duration = ANIMATION_DURATION.toLong()
+            interpolator = DecelerateInterpolator()
+        }
+        val alphaAnimator = ObjectAnimator.ofFloat(tv_describe, "alpha", 0f, 1f)
+        alphaAnimator.apply {
+            duration = ANIMATION_DURATION.toLong()
+        }
+        val animatorSet = AnimatorSet()
+        animatorSet.playTogether(translationAnim, alphaAnimator)
+        animatorSet.start()
+
+        if (position == mViewPager.data.size - 1 && btn_start?.visibility == View.GONE) {
+            btn_start?.visibility = View.VISIBLE
+            ObjectAnimator
+                .ofFloat(btn_start, "alpha", 0f, 1f)
+                .setDuration(ANIMATION_DURATION.toLong())
+                .start()
+        } else {
+            btn_start?.visibility = View.GONE
+        }
     }
-  }
 
-  companion object {
-    private const val ANIMATION_DURATION = 1300
-  }
+    companion object {
+        private const val ANIMATION_DURATION = 1300
+        private const val MIN_SCALE = 0.9f
+        private const val MIN_ALPHA = 0.7f
+    }
 }

+ 1 - 1
app/src/main/java/com/example/zhpan/banner/adapter/others/AdapterFragmentPager.kt

@@ -18,7 +18,7 @@ class AdapterFragmentPager(fragmentActivity: FragmentActivity) : FragmentStateAd
   override fun createFragment(position: Int): Fragment {
     return when (position) {
       PAGE_HOME -> HomeFragment.getInstance();
-      PAGE_FIND -> PageFragment.getInstance();
+      PAGE_FIND -> PageFragment.instance;
       PAGE_INDICATOR -> IndicatorFragment.getInstance();
       PAGE_OTHERS -> OthersFragment.getInstance();
       else -> EmptyFragment.getInstance();

+ 0 - 129
app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.java

@@ -1,129 +0,0 @@
-package com.example.zhpan.banner.fragment;
-
-import android.os.Bundle;
-import android.view.View;
-import android.widget.RadioGroup;
-
-import com.blankj.utilcode.util.ToastUtils;
-import com.example.zhpan.banner.R;
-import com.example.zhpan.banner.adapter.ViewBindingSampleAdapter;
-import com.zhpan.bannerview.BannerViewPager;
-import com.zhpan.bannerview.annotation.APageStyle;
-import com.zhpan.bannerview.constants.PageStyle;
-import com.zhpan.bannerview.utils.BannerUtils;
-import com.zhpan.indicator.enums.IndicatorSlideMode;
-
-/**
- * Created by zhpan on 2018/7/24.
- */
-public class PageFragment extends BaseFragment {
-  private BannerViewPager<Integer> mViewPager;
-  private RadioGroup mRadioGroupPageStyle;
-
-  @Override
-  protected int getLayout() {
-    return R.layout.fragment_find;
-  }
-
-  public static PageFragment getInstance() {
-    return new PageFragment();
-  }
-
-  @Override
-  protected void initTitle() {
-
-  }
-
-  @Override
-  protected void initView(Bundle savedInstanceState, View view) {
-    mViewPager = view.findViewById(R.id.banner_view);
-    mRadioGroupPageStyle = view.findViewById(R.id.rg_page_style);
-    mViewPager
-        .setIndicatorSlideMode(IndicatorSlideMode.SCALE)
-        .setIndicatorSliderColor(getColor(R.color.red_normal_color),
-            getColor(R.color.red_checked_color))
-        .setIndicatorSliderRadius(getResources().getDimensionPixelOffset(R.dimen.dp_4),
-            getResources().getDimensionPixelOffset(R.dimen.dp_5))
-        .setLifecycleRegistry(getLifecycle())
-        .setOnPageClickListener(this::pageClick)
-        .setAdapter(
-            new ViewBindingSampleAdapter(getResources().getDimensionPixelOffset(R.dimen.dp_8)))
-        .setInterval(5000);
-    initRadioGroup();
-    view.findViewById(R.id.rb_multi_page_overlap).performClick();
-  }
-
-  private void pageClick(View view, int position) {
-    if (position != mViewPager.getCurrentItem()) {
-      mViewPager.setCurrentItem(position, true);
-    }
-    ToastUtils.showShort("position:" + position);
-  }
-
-  private void initRadioGroup() {
-    mRadioGroupPageStyle.setOnCheckedChangeListener((group, checkedId) -> {
-      if (checkedId == R.id.rb_multi_page) {
-        setupMultiPageBanner();
-      } else if (checkedId == R.id.rb_right_page_reveal) {
-        setupRightPageReveal();
-      } else if (checkedId == R.id.rb_multi_page_scale) {
-        setupBanner(PageStyle.MULTI_PAGE_SCALE);
-      } else if (checkedId == R.id.rb_multi_page_overlap) {
-        setupBanner(PageStyle.MULTI_PAGE_OVERLAP);
-      } else if (checkedId == R.id.rb_netease_music_style) {
-        setNetEaseMusicStyle();
-      } else if (checkedId == R.id.rb_qq_music_style) {
-        setQQMusicStyle();
-      }
-    });
-  }
-
-  private void setupMultiPageBanner() {
-    mViewPager
-        .setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_10))
-        .setRevealWidth(getResources().getDimensionPixelOffset(R.dimen.dp_10))
-        .create(getPicList(4));
-    mViewPager.removeDefaultPageTransformer();
-  }
-
-  private void setupRightPageReveal() {
-    mViewPager
-        .setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_10))
-        .setRevealWidth(0, getResources().getDimensionPixelOffset(R.dimen.dp_30))
-        .create(getPicList(4));
-
-    mViewPager.removeDefaultPageTransformer();
-  }
-
-  private void setupBanner(@APageStyle int pageStyle) {
-    mViewPager
-        .setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_15))
-        .setRevealWidth(getResources().getDimensionPixelOffset(R.dimen.dp_10))
-        .setPageStyle(pageStyle)
-        .create(getPicList(4));
-  }
-
-  // 网易云音乐样式
-  private void setNetEaseMusicStyle() {
-    mViewPager
-        .setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_20))
-        .setRevealWidth(getResources().getDimensionPixelOffset(R.dimen.dp_m_10))
-        .setIndicatorSliderColor(getColor(R.color.red_normal_color),
-            getColor(R.color.red_checked_color))
-        .setOnPageClickListener((view, position) -> ToastUtils.showShort("position:" + position))
-        .setInterval(5000).create(getPicList(4));
-    mViewPager.removeDefaultPageTransformer();
-  }
-
-  //  仿QQ音乐的Banner
-  private void setQQMusicStyle() {
-    mViewPager
-        .setPageMargin(getResources().getDimensionPixelOffset(R.dimen.dp_15))
-        .setRevealWidth(BannerUtils.dp2px(0))
-        .setIndicatorSliderColor(getColor(R.color.red_normal_color),
-            getColor(R.color.red_checked_color))
-        .setOnPageClickListener((view, position) -> ToastUtils.showShort("position:" + position))
-        .setInterval(5000).create(getPicList(4));
-    mViewPager.removeDefaultPageTransformer();
-  }
-}

+ 198 - 0
app/src/main/java/com/example/zhpan/banner/fragment/PageFragment.kt

@@ -0,0 +1,198 @@
+package com.example.zhpan.banner.fragment
+
+import android.os.Bundle
+import android.view.View
+import android.widget.RadioGroup
+import com.blankj.utilcode.util.ToastUtils
+import com.example.zhpan.banner.R
+import com.example.zhpan.banner.R.color
+import com.example.zhpan.banner.R.dimen
+import com.example.zhpan.banner.adapter.ViewBindingSampleAdapter
+import com.zhpan.bannerview.BannerViewPager
+import com.zhpan.bannerview.annotation.APageStyle
+import com.zhpan.bannerview.constants.PageStyle
+import com.zhpan.bannerview.utils.BannerUtils
+import com.zhpan.indicator.enums.IndicatorSlideMode
+
+/**
+ * Created by zhpan on 2018/7/24.
+ */
+class PageFragment : BaseFragment() {
+    private lateinit var mViewPager: BannerViewPager<Int>
+    private lateinit var mRadioGroupPageStyle: RadioGroup
+    private lateinit var mRadioGroupMoreStyle: RadioGroup
+    override val layout: Int
+        get() = R.layout.fragment_find
+
+    override fun initTitle() {}
+    override fun initView(savedInstanceState: Bundle?, view: View) {
+        mViewPager = view.findViewById(R.id.banner_view)
+        mRadioGroupPageStyle = view.findViewById(R.id.rg_page_style)
+        mRadioGroupMoreStyle = view.findViewById(R.id.rg_more_page_style)
+        initBVP()
+        initRadioGroup()
+        view.findViewById<View>(R.id.rb_multi_page_overlap).performClick()
+    }
+
+    private fun initBVP() {
+        mViewPager.apply {
+            setLifecycleRegistry(lifecycle)
+            adapter = ViewBindingSampleAdapter(resources.getDimensionPixelOffset(dimen.dp_8))
+            setIndicatorSlideMode(IndicatorSlideMode.SCALE)
+            setIndicatorSliderColor(
+                getColor(color.red_normal_color),
+                getColor(color.red_checked_color)
+            )
+            setIndicatorSliderRadius(
+                resources.getDimensionPixelOffset(dimen.dp_4),
+                resources.getDimensionPixelOffset(dimen.dp_5)
+            )
+            setOnPageClickListener { _: View, position: Int -> itemClick(position) }
+            setInterval(5000)
+        }
+    }
+
+    private fun initRadioGroup() {
+        mRadioGroupPageStyle.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
+            when (checkedId) {
+                R.id.rb_multi_page_overlap ->
+                    setupBanner(
+                        PageStyle.MULTI_PAGE_OVERLAP,
+                        resources.getDimensionPixelOffset(dimen.dp_10)
+                    )
+                R.id.rb_multi_page_overlap1 ->
+                    setupBanner(
+                        PageStyle.MULTI_PAGE_OVERLAP,
+                        resources.getDimensionPixelOffset(dimen.dp_100)
+                    )
+                R.id.rb_multi_page_scale ->
+                    setupBanner(
+                        PageStyle.MULTI_PAGE_SCALE,
+                        resources.getDimensionPixelOffset(dimen.dp_10)
+                    )
+                R.id.rb_multi_scale_page2 ->
+                    setupBanner(
+                        PageStyle.MULTI_PAGE_SCALE,
+                        resources.getDimensionPixelOffset(dimen.dp_120)
+                    )
+                R.id.rb_multi_scale_page3 -> {
+                    setupBanner(
+                        PageStyle.MULTI_PAGE_SCALE,
+                        resources.getDimensionPixelOffset(dimen.dp_0),
+                        resources.getDimensionPixelOffset(dimen.dp_200)
+                    )
+                }
+            }
+        }
+        mRadioGroupMoreStyle.setOnCheckedChangeListener { _: RadioGroup?, checkedId: Int ->
+            when (checkedId) {
+                R.id.rb_multi_page3 ->
+                    setupMultiPageBanner()
+                R.id.rb_multi_page4 ->
+                    setupRightPageReveal()
+                R.id.rb_netease_music_style ->
+                    setNetEaseMusicStyle()
+                R.id.rb_qq_music_style ->
+                    setQQMusicStyle()
+            }
+        }
+    }
+
+    /**
+     * Different page styles can be implement by use [BannerViewPager.setPageStyle] and
+     * [BannerViewPager.setRevealWidth]
+     *
+     * @param pageStyle Optional params [PageStyle.MULTI_PAGE_SCALE] and [PageStyle.MULTI_PAGE_OVERLAP]
+     * @param revealWidth In the multi-page mode, The exposed width of the items on the left and right sides
+     */
+    private fun setupBanner(@APageStyle pageStyle: Int, revealWidth: Int) {
+        setupBanner(pageStyle, revealWidth, revealWidth)
+    }
+
+    private fun setupBanner(
+        @APageStyle pageStyle: Int,
+        leftRevealWidth: Int,
+        rightRevealWidth: Int
+    ) {
+        mViewPager
+            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_15))
+            .setScrollDuration(800)
+            .setRevealWidth(leftRevealWidth, rightRevealWidth)
+            .setPageStyle(pageStyle)
+            .create(getPicList(4))
+    }
+
+    /**
+     * Multi Page Style 1
+     */
+    private fun setupMultiPageBanner() {
+        mViewPager
+            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_10))
+            .setRevealWidth(resources.getDimensionPixelOffset(dimen.dp_10))
+            .create(getPicList(4))
+        mViewPager.removeDefaultPageTransformer()
+    }
+
+    /**
+     * Multi Page Style 2
+     */
+    private fun setupRightPageReveal() {
+        mViewPager
+            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_10))
+            .setRevealWidth(0, resources.getDimensionPixelOffset(dimen.dp_30))
+            .create(getPicList(4))
+        mViewPager.removeDefaultPageTransformer()
+    }
+
+    /**
+     * QQ Music Banner Style
+     */
+    private fun setNetEaseMusicStyle() {
+        mViewPager
+            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_20))
+            .setRevealWidth(resources.getDimensionPixelOffset(dimen.dp_m_10))
+            .setIndicatorSliderColor(
+                getColor(color.red_normal_color),
+                getColor(color.red_checked_color)
+            )
+            .setOnPageClickListener { view: View?, position: Int ->
+                ToastUtils.showShort(
+                    "position:$position"
+                )
+            }
+            .setInterval(5000).create(getPicList(4))
+        mViewPager.removeDefaultPageTransformer()
+    }
+
+    /**
+     * NetEase Music Banner Style
+     */
+    private fun setQQMusicStyle() {
+        mViewPager
+            .setPageMargin(resources.getDimensionPixelOffset(dimen.dp_15))
+            .setRevealWidth(BannerUtils.dp2px(0f))
+            .setIndicatorSliderColor(
+                getColor(color.red_normal_color),
+                getColor(color.red_checked_color)
+            )
+            .setOnPageClickListener { _: View?, position: Int ->
+                ToastUtils.showShort(
+                    "position:$position"
+                )
+            }
+            .setInterval(5000).create(getPicList(4))
+        mViewPager.removeDefaultPageTransformer()
+    }
+
+    private fun itemClick(position: Int) {
+        if (position != mViewPager.currentItem) {
+            mViewPager.setCurrentItem(position, true)
+        }
+        ToastUtils.showShort("position:$position")
+    }
+
+    companion object {
+        val instance: PageFragment
+            get() = PageFragment()
+    }
+}

+ 0 - 45
app/src/main/java/com/example/zhpan/banner/transform/DepthPageTransformer.java

@@ -1,45 +0,0 @@
-/*
- * Copyright 2014 Toxic Bakery
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.zhpan.banner.transform;
-
-import android.view.View;
-
-public class DepthPageTransformer extends BaseTransformer {
-
-  private static final float MIN_SCALE = 0.75f;
-
-  @Override
-  protected void onTransform(View view, float position) {
-    if (position <= 0f) {
-      view.setTranslationX(0f);
-      view.setScaleX(1f);
-      view.setScaleY(1f);
-    } else if (position <= 1f) {
-      final float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
-      view.setAlpha(1 - position);
-      view.setPivotY(0.5f * view.getHeight());
-      view.setTranslationX(view.getWidth() * -position);
-      view.setScaleX(scaleFactor);
-      view.setScaleY(scaleFactor);
-    }
-  }
-
-  @Override
-  protected boolean isPagingEnabled() {
-    return true;
-  }
-}

+ 31 - 0
app/src/main/java/com/example/zhpan/banner/transform/DepthPageTransformer.kt

@@ -0,0 +1,31 @@
+
+package com.example.zhpan.banner.transform
+
+import android.view.View
+import androidx.viewpager2.widget.ViewPager2
+
+class DepthPageTransformer : ViewPager2.PageTransformer {
+
+    override fun transformPage(page: View, position: Float) {
+        page.also {
+            if (kotlin.math.abs(position) >= 1f) {
+                it.alpha = 0f
+                return@transformPage
+            }
+            if (position > 0) {
+                it.alpha = 1 - position
+                val scale = 1f - position / 4f
+                it.scaleX = scale
+                it.scaleY = scale
+                it.translationX = -it.width * position
+                it.translationZ = -1f
+            } else {
+                it.alpha = 1f
+                it.scaleX = 1f
+                it.scaleY = 1f
+                it.translationX = 0f
+                it.translationZ = 0f
+            }
+        }
+    }
+}

+ 27 - 0
app/src/main/java/com/example/zhpan/banner/transform/DepthScaleTransformer.kt

@@ -0,0 +1,27 @@
+
+package com.example.zhpan.banner.transform
+
+import android.view.View
+import androidx.viewpager2.widget.ViewPager2
+
+class DepthScaleTransformer :  ViewPager2.PageTransformer {
+
+    companion object {
+        private const val MIN_SCALE = 0.9f
+        private const val MIN_ALPHA = 0.7f
+    }
+
+    override fun transformPage(page: View, position: Float) {
+        page.also {
+            if (kotlin.math.abs(position) >= 1f) {
+                it.alpha = 0f
+                return@transformPage
+            }
+            val scale = (1 - kotlin.math.abs(position) / 2).coerceAtLeast(MIN_SCALE)
+            it.scaleX = scale
+            it.scaleY = scale
+            it.alpha = (1 - kotlin.math.abs(position)).coerceAtLeast(MIN_ALPHA)
+            it.translationX = (1 - scale) * it.width / 2 * if (position > 0) -1 else 1
+        }
+    }
+}

+ 7 - 3
app/src/main/java/com/example/zhpan/banner/transform/PageTransformerFactory.java

@@ -6,9 +6,10 @@ import com.zhpan.bannerview.transform.ScaleInTransformer;
 
 import static com.example.zhpan.banner.transform.TransformerStyle.ACCORDION;
 import static com.example.zhpan.banner.transform.TransformerStyle.DEPTH;
+import static com.example.zhpan.banner.transform.TransformerStyle.DEPTH_SCALE;
 import static com.example.zhpan.banner.transform.TransformerStyle.ROTATE;
+import static com.example.zhpan.banner.transform.TransformerStyle.ROTATE_UP;
 import static com.example.zhpan.banner.transform.TransformerStyle.SCALE_IN;
-import static com.example.zhpan.banner.transform.TransformerStyle.STACK;
 
 public class PageTransformerFactory {
 
@@ -19,10 +20,13 @@ public class PageTransformerFactory {
         transformer = new DepthPageTransformer();
         break;
       case ROTATE:
+        transformer = new RotateTransformer();
+        break;
+      case ROTATE_UP:
         transformer = new RotateUpTransformer();
         break;
-      case STACK:
-        transformer = new StackTransformer();
+      case DEPTH_SCALE:
+        transformer = new DepthScaleTransformer();
         break;
       case ACCORDION:
         transformer = new AccordionTransformer();

+ 28 - 0
app/src/main/java/com/example/zhpan/banner/transform/RotateTransformer.kt

@@ -0,0 +1,28 @@
+
+package com.example.zhpan.banner.transform
+
+import android.view.View
+import androidx.viewpager2.widget.ViewPager2
+import kotlin.math.abs
+
+class RotateTransformer  : ViewPager2.PageTransformer {
+    override fun transformPage(page: View, position: Float) {
+        page.also {
+            if (abs(position) >= 1f) {
+                it.alpha = 0f
+                return@transformPage
+            }
+            val scale = (1 - abs(position)).coerceAtLeast(MIN_SCALE)
+            it.scaleX = scale
+            it.scaleY = scale
+            it.alpha = 1f
+            it.translationX = (1 - scale) * it.width / 2 * if (position > 0) -1 else 1
+            it.translationZ = if (scale == MIN_SCALE) -1f else 0f
+            it.rotation = -position * 45
+        }
+    }
+
+    companion object{
+        private const val MIN_SCALE = 0.5f
+    }
+}

+ 0 - 27
app/src/main/java/com/example/zhpan/banner/transform/StackTransformer.java

@@ -1,27 +0,0 @@
-/*
- * Copyright 2014 Toxic Bakery
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.zhpan.banner.transform;
-
-import android.view.View;
-
-public class StackTransformer extends BaseTransformer {
-
-  @Override
-  protected void onTransform(View view, float position) {
-    view.setTranslationX(position < 0 ? 0f : -view.getWidth() * position);
-  }
-}

+ 6 - 5
app/src/main/java/com/example/zhpan/banner/transform/TransformerStyle.java

@@ -2,9 +2,10 @@ package com.example.zhpan.banner.transform;
 
 public interface TransformerStyle {
   int NONE = 0;
-  int DEPTH = 1 << 1;
-  int STACK = 1 << 2;
-  int ACCORDION = 1 << 3;
-  int ROTATE = 1 << 4;
-  int SCALE_IN = 1 << 5;
+  int DEPTH = 1;
+  int DEPTH_SCALE = 2;
+  int ACCORDION = 3;
+  int ROTATE = 4;
+  int ROTATE_UP=5;
+  int SCALE_IN = 6;
 }

+ 119 - 69
app/src/main/res/layout/fragment_find.xml

@@ -1,90 +1,140 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
-
-  <com.zhpan.bannerview.BannerViewPager
-      android:id="@+id/banner_view"
-      android:layout_width="match_parent"
-      android:layout_height="@dimen/dp_185"
-      android:layout_marginTop="@dimen/dp_16"
-      app:bvp_indicator_slide_mode="worm"
-      app:bvp_page_style="multi_page" />
-
-  <TextView
-      android:id="@+id/tv_page_style"
-      android:layout_width="wrap_content"
-      android:layout_height="wrap_content"
-      android:layout_below="@id/banner_view"
-      android:layout_marginStart="@dimen/dp_10"
-      android:layout_marginTop="@dimen/dp_10"
-      android:text="@string/text_page_style"
-      android:textColor="#000000"
-      android:textSize="@dimen/sp_18"
-      android:textStyle="bold" />
-
-  <RadioGroup
-      android:id="@+id/rg_page_style"
+  <LinearLayout
       android:layout_width="match_parent"
-      android:layout_height="wrap_content"
-      android:layout_below="@id/tv_page_style"
-      android:padding="@dimen/dp_15">
+      android:orientation="vertical"
+      android:layout_height="match_parent">
 
+    <com.zhpan.bannerview.BannerViewPager
+        android:id="@+id/banner_view"
+        android:layout_width="match_parent"
+        android:layout_height="@dimen/dp_185"
+        android:layout_marginTop="@dimen/dp_16"
+        app:bvp_indicator_slide_mode="worm"
+        app:bvp_page_style="multi_page" />
 
-    <RadioButton
-        android:id="@+id/rb_multi_page_overlap"
+    <TextView
+        android:id="@+id/tv_page_style"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/dp_15"
-        android:text="MULTI_PAGE_OVERLAP"
-        android:textSize="@dimen/sp_16" />
-
+        android:layout_below="@id/banner_view"
+        android:layout_marginStart="@dimen/dp_10"
+        android:layout_marginTop="@dimen/dp_10"
+        android:text="@string/text_page_style"
+        android:textColor="#000000"
+        android:textSize="@dimen/sp_18"
+        android:textStyle="bold" />
 
-    <RadioButton
-        android:id="@+id/rb_multi_page_scale"
-        android:layout_width="wrap_content"
+    <RadioGroup
+        android:id="@+id/rg_page_style"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/dp_15"
-        android:text="MULTI_PAGE_SCALE"
-        android:textSize="@dimen/sp_16" />
+        android:layout_below="@id/tv_page_style"
+        android:padding="@dimen/dp_15">
 
-    <RadioButton
-        android:id="@+id/rb_multi_page"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginEnd="@dimen/dp_15"
-        android:layout_marginTop="@dimen/dp_15"
-        android:text="Two Sides Page Reveal"
 
-        android:textSize="@dimen/sp_16" />
+      <RadioButton
+          android:id="@+id/rb_multi_page_overlap"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="MULTI_PAGE_OVERLAP Style 1"
+          android:textSize="@dimen/sp_16" />
 
-    <RadioButton
-        android:id="@+id/rb_right_page_reveal"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginEnd="@dimen/dp_15"
-        android:layout_marginTop="@dimen/dp_15"
-        android:text="Right Page Reveal"
-        android:textSize="@dimen/sp_16" />
+      <RadioButton
+          android:id="@+id/rb_multi_page_overlap1"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginEnd="@dimen/dp_15"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="MULTI_PAGE_OVERLAP Style 2"
+          android:textSize="@dimen/sp_16" />
 
-    <RadioButton
-        android:id="@+id/rb_qq_music_style"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/dp_15"
-        android:text="QQ Music Banner Style"
-        android:textSize="@dimen/sp_16" />
+      <RadioButton
+          android:id="@+id/rb_multi_page_scale"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="MULTI_PAGE_SCALE Style 1"
+          android:textSize="@dimen/sp_16" />
+
+      <RadioButton
+          android:id="@+id/rb_multi_scale_page2"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginEnd="@dimen/dp_15"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="MULTI_PAGE_SCALE Style 2"
+          android:textSize="@dimen/sp_16" />
+
+      <RadioButton
+          android:id="@+id/rb_multi_scale_page3"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginEnd="@dimen/dp_15"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="MULTI_PAGE_SCALE Style 3"
+          android:textSize="@dimen/sp_16" />
 
-    <RadioButton
-        android:id="@+id/rb_netease_music_style"
+    </RadioGroup>
+
+    <TextView
+        android:id="@+id/tv_page_style_more"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/dp_15"
-        android:text="NetEase Music Banner Style"
-        android:textSize="@dimen/sp_16" />
+        android:layout_below="@id/banner_view"
+        android:layout_marginStart="@dimen/dp_10"
+        android:layout_marginTop="@dimen/dp_10"
+        android:text="@string/text_page_style_more"
+        android:textColor="#000000"
+        android:textSize="@dimen/sp_18"
+        android:textStyle="bold" />
+
+    <RadioGroup
+        android:id="@+id/rg_more_page_style"
+        android:layout_width="match_parent"
+        android:padding="@dimen/dp_15"
+        android:layout_height="wrap_content">
+
+      <RadioButton
+          android:id="@+id/rb_multi_page3"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginEnd="@dimen/dp_15"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="Multi Page Style 1"
+          android:textSize="@dimen/sp_16" />
+
+      <RadioButton
+          android:id="@+id/rb_multi_page4"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginEnd="@dimen/dp_15"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="Multi Page Style 2"
+          android:textSize="@dimen/sp_16" />
+
+      <RadioButton
+          android:id="@+id/rb_qq_music_style"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="QQ Music Banner Style"
+          android:textSize="@dimen/sp_16" />
+
+      <RadioButton
+          android:id="@+id/rb_netease_music_style"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:layout_marginTop="@dimen/dp_15"
+          android:text="NetEase Music Banner Style"
+          android:textSize="@dimen/sp_16" />
 
 
-  </RadioGroup>
+    </RadioGroup>
 
-</RelativeLayout>
+  </LinearLayout>
+</androidx.core.widget.NestedScrollView>

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -42,5 +42,5 @@
     <string name="user_registered">该账户已存在</string>
     <string name="wrong_password">密码错误</string>
     <string name="remote_login">您的账号已在其它设备上登录,如非本人操作,请及时修改密码!</string>
-  <string name="text_page_style_more">More Page Style:</string>
+  <string name="text_page_style_more">More Page Styles:</string>
 </resources>

+ 10 - 6
bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java

@@ -1012,10 +1012,11 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
   }
 
   /**
-   * Set Page Style for Banner
+   * Set the default PageTrans former for {@link ViewPager2}
+   * Option params:
+   * {@link PageStyle#MULTI_PAGE_OVERLAP}
+   * {@link PageStyle#MULTI_PAGE_SCALE}
    * {@link PageStyle#NORMAL}
-   *
-   * @return BannerViewPager
    */
   public BannerViewPager<T> setPageStyle(@APageStyle int pageStyle) {
     return setPageStyle(pageStyle, DEFAULT_MIN_SCALE);
@@ -1028,7 +1029,8 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
   }
 
   /**
-   * @param revealWidth 一屏多页模式下两边页面显露出来的宽度
+   * @param revealWidth In the multi-page mode, The exposed width of the items on the left and right
+   * sides
    */
   public BannerViewPager<T> setRevealWidth(int revealWidth) {
     setRevealWidth(revealWidth, revealWidth);
@@ -1036,8 +1038,10 @@ public class BannerViewPager<T> extends RelativeLayout implements LifecycleObser
   }
 
   /**
-   * @param leftRevealWidth left page item  reveal width
-   * @param rightRevealWidth right page item reveal width
+   * This method is apply to multi-page mode {@link #setPageStyle(int)}
+   *
+   * @param leftRevealWidth The exposed width of left side
+   * @param rightRevealWidth The exposed width of right side
    */
   public BannerViewPager<T> setRevealWidth(int leftRevealWidth, int rightRevealWidth) {
     mBannerManager.getBannerOptions().setRightRevealWidth(rightRevealWidth);