Skip to content

Commit

Permalink
v2.4.3 (#30)
Browse files Browse the repository at this point in the history
更换轮播方案
Add New API setOnPageChangeListener
Add New Api disabledTouchScroll
  • Loading branch information
zhpanvip authored Nov 19, 2019
1 parent 454ee03 commit 3b301fd
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 116 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ BannerViewPager支持多种IndicatorViewStyle,同时还提供了完全自定义I
| BannerViewPager<T, VH> setIndicatorStyle(int indicatorStyle) | 设置指示器样式 | 可选枚举(CIRCLE, DASH) 默认CIRCLE |
| BannerViewPager<T, VH> setIndicatorGravity(int gravity) | 指示器位置 |可选值(CENTER、START、END)默认值CENTER |
| BannerViewPager<T, VH> setIndicatorColor(int normalColor,int checkedColor) | 指示器圆点颜色 |normalColor:未选中时颜色默认"#8C6C6D72", checkedColor:选中时颜色 默认"#8C18171C" |
| BannerViewPager<T, VH> setIndicatorSlideMode(int slideMode) | 设置Indicator滑动模式 | 可选(NORMAL、SMOOTH),默认值SMOOTH |
| BannerViewPager<T, VH> setIndicatorSlideMode(int slideMode) | 设置Indicator滑动模式 | 可选(NORMAL、SMOOTH),默认值NORMAL |
| BannerViewPager<T, VH> setIndicatorRadius(int radius) | 设置指示器圆点半径 | 默认值4dp|
| BannerViewPager<T, VH> setIndicatorRadius(int normalRadius,int checkRadius) |设置指示器圆点半径 | normalRadius:未选中时半径 checkedRadius:选中时的半径,默认值4dp |
| BannerViewPager<T, VH> setIndicatorWidth(int indicatorWidth) | 设置指示器宽度,如果是圆形指示器,则为直径 | 默认值8dp|
| BannerViewPager<T, VH> setIndicatorWidth(int normalWidth, int checkWidth) | 设置指示器宽度,如果是圆形指示器,则为直径 | 默认值8dp |
| BannerViewPager<T, VH> setIndicatorHeight(int indicatorHeight) | 设置指示器高度,仅在Indicator样式为DASH时有效 | 默认值normalIndicatorWidth/2 |
| BannerViewPager<T, VH> setIndicatorGap(int indicatorMargin) | 指示器圆点间距| 默认值为指示器宽度(或者是圆的直径)|
| BannerViewPager<T, VH> setIndicatorView(IIndicator indicatorView) | 设置自定义指示器| |
| BannerViewPager<T, VH> setIndicatorView(IIndicator indicatorView) | 设置自定义指示器|自定义View需要继承BaseIndicatorView或实现IIndicator |
| BannerViewPager<T, VH> setPageTransformerStyle(int style) | 设置页面Transformer内置样式 | |
| BannerViewPager<T, VH> setCurrentItem(int item) | Set the currently selected page. | 2.3.5新增 |
| void getCurrentItem() | 获取当前position | 2.3.5新增 |
| int getCurrentItem() | 获取当前position | 2.3.5新增 |
| BannerViewPager<T, VH> setPageStyle(PageStyle pageStyle) | 设置页面样式 | 2.4.0新增 可选(MULTI_PAGE、NORMAL)MULTI_PAGE:一屏多页样式 |
| BannerViewPager<T, VH> setPageMargin(int pageMargin) | 设置页面间隔 | 2.4.0新增 |
| BannerViewPager<T, VH> setIndicatorMargin(int left, int top, int right, int bottom) | 设置Indicator边距 | 2.4.1新增 |
Expand All @@ -84,7 +84,7 @@ BannerViewPager支持多种IndicatorViewStyle,同时还提供了完全自定义I
### xml支持的attrs
| Attributes | format | description |
|--|--|--|
| bvp_interval | integer | 自动轮播事件间隔 |
| bvp_interval | integer | 自动轮播时间间隔 |
| bvp_scroll_duration | integer | 页面切换时滑动时间|
| bvp_can_loop | boolean| 是否循环 |
| bvp_auto_play | boolean | 是否自动播放 |
Expand Down Expand Up @@ -258,6 +258,8 @@ public class NetViewHolder implements ViewHolder<BannerData> {
```
### 7.高级功能---自定义IndicatorView

在内置Indicator不满足需求时可以通过自定义IndicatorView实现。

**(1)自定义View并继承BaseIndicatorView**

```
Expand Down Expand Up @@ -322,6 +324,19 @@ public class FigureIndicatorView extends BaseIndicatorView {
}
}
```
** (2)设置自定义指示器 **

```
FigureIndicatorView indicatorView = new FigureIndicatorView(mContext);
indicatorView.setRadius(BannerUtils.dp2px(18));
indicatorView.setTextSize(BannerUtils.dp2px(13));
indicatorView.setBackgroundColor(Color.parseColor("#aa118EEA"));
mViewPager.setIndicatorGravity(IndicatorGravity.END)
.setIndicatorView(indicatorView)
.setHolderCreator(() -> new ImageResourceViewHolder(0))
.create(mDrawableList);
```

## TODO 版本计划

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.example.zhpan.circleviewpager.activity;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -17,6 +17,7 @@
import com.zhpan.bannerview.constants.IndicatorSlideMode;
import com.zhpan.bannerview.constants.TransformerStyle;
import com.zhpan.bannerview.holder.HolderCreator;
import com.zhpan.bannerview.utils.BannerUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -38,12 +39,18 @@ public class WelcomeActivity extends BaseDataActivity implements
@BindView(R.id.btn_start)
TextView mTvStart;

@BindView(R.id.tv_describe)
TextView mTvDescription;

private static final int ANIMATION_DURATION = 1300;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
ButterKnife.bind(this);
setupViewPager();
updateUI(0);
}

@Override
Expand All @@ -57,8 +64,8 @@ private void setupViewPager() {
mViewPager.setAutoPlay(false)
.setCanLoop(false)
.setPageTransformerStyle(transforms[new Random().nextInt(5)])
.setIndicatorVisibility(View.GONE)
.setIndicatorView(findViewById(R.id.indicator))
.setScrollDuration(ANIMATION_DURATION)
.setIndicatorMargin(0, 0, 0, BannerUtils.dp2px(100))
.setIndicatorGap((int) getResources().getDimension(R.dimen.dp_10))
.setIndicatorColor(getResources().getColor(R.color.white),
getResources().getColor(R.color.white_alpha_75))
Expand All @@ -67,7 +74,7 @@ private void setupViewPager() {
.setOnPageChangeListener(new OnPageChangeListenerAdapter() {
@Override
public void onPageSelected(int position) {
showStartButton(position);
updateUI(position);
}
})
.setHolderCreator(this)
Expand All @@ -80,12 +87,22 @@ public void onClick(View view) {
finish();
}

private void showStartButton(int position) {
private void updateUI(int position) {
mTvDescription.setText(des[position]);
ObjectAnimator translationAnim = ObjectAnimator.ofFloat(mTvDescription, "translationX", -120, 0);
translationAnim.setDuration(ANIMATION_DURATION);
translationAnim.setInterpolator(new DecelerateInterpolator());
ObjectAnimator alphaAnimator1 = ObjectAnimator.ofFloat(mTvDescription, "alpha", 0, 1);
alphaAnimator1.setDuration(ANIMATION_DURATION);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(translationAnim, alphaAnimator1);
animatorSet.start();

if (position == mViewPager.getList().size() - 1 && mTvStart.getVisibility() == View.GONE) {
mTvStart.setVisibility(View.VISIBLE);
ObjectAnimator
.ofFloat(mTvStart, "alpha", 0, 1)
.setDuration(1500).start();
.setDuration(ANIMATION_DURATION).start();
} else {
mTvStart.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ private void initRadioGroup() {
radioGroupStyle.setOnCheckedChangeListener((group, checkedId) -> {
switch (checkedId) {
case R.id.rb_circle:
mViewPager.resetIndicator();
// mViewPager.resetIndicator();
setupCircleIndicator();
break;
case R.id.rb_dash:
mViewPager.resetIndicator();
// mViewPager.resetIndicator();
setupDashIndicator();
break;
case R.id.rb_custom:
Expand All @@ -78,7 +78,6 @@ private void setupCircleIndicator() {
.setIndicatorGravity(IndicatorGravity.CENTER)
.setIndicatorGap(BannerUtils.dp2px(6))
.setPageMargin(0)
.setIndicatorMargin(0, 0, 0, BannerUtils.dp2px(10))
.setOnPageClickListener(position -> ToastUtils.show("position:" + position))
.setIndicatorColor(getColor(R.color.red_normal_color), getColor(R.color.red_checked_color))
.setIndicatorRadius(BannerUtils.dp2px(4), BannerUtils.dp2px(5)).create(mDrawableList);
Expand All @@ -98,7 +97,6 @@ private void setupDashIndicator() {
private void setupCustomIndicator() {
mViewPager.setAutoPlay(false).setCanLoop(true)
.setPageMargin(BannerUtils.dp2px(20))
.setIndicatorMargin(0, 0, BannerUtils.dp2px(10), BannerUtils.dp2px(10))
.setIndicatorGravity(IndicatorGravity.END)
.setIndicatorView(setupIndicatorView())
.setHolderCreator(() -> new ImageResourceViewHolder(0)).create(mDrawableList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static PageFragment getInstance() {

private void setupBanner(@APageStyle int pageStyle) {
mViewPager
.setIndicatorVisibility(View.VISIBLE) // 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
.setPageStyle(pageStyle)
.create(mDrawableList);
}
Expand All @@ -78,12 +79,18 @@ private void initRadioGroup() {
mRadioGroupPageStyle.setOnCheckedChangeListener((group, checkedId) -> {
switch (checkedId) {
case R.id.rb_multi_page:
// mViewPager.resetIndicator();// 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
indicatorView.setVisibility(View.INVISIBLE);// 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
setupBanner(PageStyle.MULTI_PAGE);
break;
case R.id.rb_multi_page_scale:
// mViewPager.resetIndicator();// 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
indicatorView.setVisibility(View.INVISIBLE);// 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
setupBanner(PageStyle.MULTI_PAGE_SCALE);
break;
case R.id.rb_multi_page_overlap:
indicatorView.setVisibility(View.VISIBLE);// 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
// mViewPager.resetIndicator();
setupOverlapBanner();
break;
}
Expand All @@ -96,8 +103,6 @@ private void setupOverlapBanner() {
.setIndicatorVisibility(View.GONE) // 在实际开发中这行代码不必添加,此处因为受到其它两种模式影响所以要隐藏掉内置指示器
.setPageStyle(PageStyle.MULTI_PAGE_OVERLAP)
.setIndicatorView(indicatorView)
.setIndicatorColor(Color.parseColor("#888888"),
Color.parseColor("#118EEA"))
.create(mDrawableList);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,39 @@
package com.example.zhpan.circleviewpager.viewholder;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zhpan.circleviewpager.R;
import com.example.zhpan.circleviewpager.bean.CustomBean;
import com.zhpan.bannerview.holder.ViewHolder;

public class CustomPageViewHolder implements ViewHolder<CustomBean> {
private ImageView mImageView;
private TextView mTextView;
private ImageView mImageStart;
private OnSubViewClickListener mOnSubViewClickListener;

@Override
public View createView(ViewGroup viewGroup, Context context, int position) {
View view = LayoutInflater.from(context).inflate(R.layout.item_custom_view, viewGroup, false);
mImageView = view.findViewById(R.id.banner_image);
mTextView = view.findViewById(R.id.tv_describe);
mImageStart = view.findViewById(R.id.iv_logo);
return view;
}

@Override
public void onBind(Context context, CustomBean data, int position, int size) {
mImageView.setImageResource(data.getImageRes());
mTextView.setText(data.getImageDescription());
mImageStart.setOnClickListener(view -> {
if (null != mOnSubViewClickListener)
mOnSubViewClickListener.onViewClick(view, position);
});
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mImageStart, "alpha", 0, 1);
alphaAnimator.setDuration(1500);

ObjectAnimator translationAnim = ObjectAnimator.ofFloat(mTextView, "translationX", -120, 0);
translationAnim.setDuration(1500);
translationAnim.setInterpolator(new DecelerateInterpolator());

ObjectAnimator alphaAnimator1 = ObjectAnimator.ofFloat(mTextView, "alpha", 0, 1);
alphaAnimator1.setDuration(1500);

AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(alphaAnimator, translationAnim, alphaAnimator1);
animatorSet.start();
alphaAnimator.start();

}

Expand Down
11 changes: 7 additions & 4 deletions app/src/main/res/layout/activity_welcome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.zhpan.bannerview.indicator.CircleIndicatorView
android:id="@+id/indicator"
<TextView
android:id="@+id/tv_describe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp" />
android:layout_marginStart="50dp"
android:layout_marginBottom="150dp"
android:lineSpacingExtra="5dp"
android:textColor="#FFFFFF"
android:textSize="18sp" />

<TextView
android:id="@+id/btn_start"
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/layout/item_custom_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,4 @@
android:layout_marginTop="40dp"
android:src="@mipmap/ic_launcher" />

<TextView
android:id="@+id/tv_describe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="50dp"
android:layout_marginBottom="150dp"
android:lineSpacingExtra="5dp"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RelativeLayout>
Loading

0 comments on commit 3b301fd

Please sign in to comment.