Skip to content

Commit

Permalink
2.3.0发布,更新内容看release
Browse files Browse the repository at this point in the history
  • Loading branch information
crazysunj committed Nov 29, 2020
1 parent 30c2411 commit 260362d
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 371 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* page和linear两种滑动方式
* 百分比适配,但只会根据宽高其中一个维度适配
* 非无循环模式边界支持回弹,可动态设置是否开启
* 支持预加载

想实现轮播效果的同学,1.x版本可以参考[CrazyDaily](https://github.com/crazysunj/CrazyDaily "https://github.com/crazysunj/CrazyDaily")开源项目首页实现,2.x版本可以参考本项目实例,还有炫酷的指示器、3D旋转和倒影效果哦

Expand Down
4 changes: 3 additions & 1 deletion README_2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public static Bitmap convertReflection(@NonNull Bitmap originalImage, int viewWi
<attr name="card_side_offset_percent" format="float" />
// item的宽高比
<attr name="card_item_rate" format="float" />
// 预加载数量,默认0
<attr name="card_page_limit" format="integer" />
// 滑动模式,page-类似ViewPager,linear-类似平时RecyclerView(有作滑动优化)
<attr name="card_page_mode" format="enum">
<enum name="linear" value="0" />
Expand All @@ -145,7 +147,7 @@ public static Bitmap convertReflection(@NonNull Bitmap originalImage, int viewWi
## gradle依赖

```
implementation 'com.crazysunj:cardslideview:2.2.1'
implementation 'com.crazysunj:cardslideview:2.3.0'
同时还需要依赖自己的v4包和recyclerview包,androidx哦
```

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation project(':cardslideview')
implementation 'com.crazysunj:cardslideview:2.2.1'
implementation 'com.crazysunj:cardslideview:2.3.0'
// implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.github.bumptech.glide:glide:4.11.0'
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/crazysunj/cardslide/BannerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@


/**
* banner控件,基于RecyclerView,由于还未使用androidX,没用上ViewPager2,完全靠摸索调试自测
* 发现任何展示错误,请联系我,描述场景以及错误异常
*
* @author sunjian
* @date 2019-12-30 10:09
*/
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/view_banner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
app:card_item_margin_percent="-0.84"
app:card_item_rate="0.7"
app:card_loop="true"
app:card_page_limit="1"
app:card_page_mode="page"
app:card_side_offset_percent="0.24" />

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ext {
userOrg = 'twsunj'
groupId = 'com.crazysunj'
uploadName = 'CardSlideView'
publishVersion = '2.2.1'
publishVersion = '2.3.0'
desc = 'CardSlideView For Android'
website = 'https://github.com/crazysunj/CardSlideView'
licences = ['Apache-2.0']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ private void initView(Context context, @Nullable AttributeSet attrs) {
// item之间间距,可设负值(叠加),百分比是相对自身宽度或高度
final float itemMarginPercent;
final boolean isRebound;
// 预加载数量,默认0
final int pageLimit;
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardSlideView);
mSideOffsetPercent = ta.getFloat(R.styleable.CardSlideView_card_side_offset_percent, 0.25f);
Expand All @@ -150,6 +152,7 @@ private void initView(Context context, @Nullable AttributeSet attrs) {
itemMarginPercent = Math.min(1, Math.max(-1, ta.getFloat(R.styleable.CardSlideView_card_item_margin_percent, 0f)));
orientation = ta.getInt(R.styleable.CardSlideView_android_orientation, LinearLayout.HORIZONTAL);
cardMode = ta.getInt(R.styleable.CardSlideView_card_page_mode, MODE_PAGE);
pageLimit = ta.getInteger(R.styleable.CardSlideView_card_page_limit, 0);
ta.recycle();
} else {
mSideOffsetPercent = 0.25f;
Expand All @@ -159,6 +162,7 @@ private void initView(Context context, @Nullable AttributeSet attrs) {
itemMarginPercent = 0;
orientation = LinearLayout.HORIZONTAL;
cardMode = MODE_PAGE;
pageLimit = 0;
}
mSideOffsetPercent = Math.min(1, Math.max(0, mSideOffsetPercent));
mCardListView = new InnerRecyclerView(context);
Expand All @@ -169,6 +173,7 @@ private void initView(Context context, @Nullable AttributeSet attrs) {
mCardListView.setItemMarginPercent(itemMarginPercent);
addView(mCardListView);
mLayoutManager = new GalleryLayoutManager(orientation, mIsLoop, isRebound, itemMarginPercent);
mLayoutManager.setOffscreenPageLimit(pageLimit);
mLayoutManager.setItemTransformer(new DefaultTransformer());
mLayoutManager.attachToRecyclerView(mCardListView);
}
Expand Down Expand Up @@ -316,8 +321,12 @@ public void setItemTransformer(PageTransformer pageTransformer) {
mLayoutManager.setItemTransformer(pageTransformer);
}

public void setOnPageChangeListener(OnPageChangeListener onPageChangeListener) {
mLayoutManager.setOnPageChangeListener(onPageChangeListener);
public void setOnPageScrollStateChangeListener(OnPageScrollStateChangeListener listener) {
mLayoutManager.setOnPageScrollStateChangeListener(listener);
}

public void setOnPageChangeListener(OnPageChangeListener listener) {
mLayoutManager.setOnPageChangeListener(listener);
}

public void setOnPageItemClickListener(OnPageItemClickListener<T> listener) {
Expand Down Expand Up @@ -456,7 +465,7 @@ public boolean onFling(int velocityX, int velocityY) {
if (centerView != null) {
final OrientationHelper helper = galleryLayoutManager.getOrientationHelper();
final int childSize = helper.getDecoratedMeasurement(centerView);
final int itemDist = (int) (childSize * (1.f + itemMarginPercent) + 0.5f);
final int itemDist = childSize + (int) (childSize * itemMarginPercent);
final int orientation = galleryLayoutManager.getOrientation();
final int velocity = orientation == LinearLayout.HORIZONTAL ? velocityX : velocityY;
final int count = mode == MODE_PAGE ? 1 : (int) (getDist(velocityX, velocityY, orientation) / itemDist * countRate);
Expand All @@ -470,9 +479,7 @@ public boolean onFling(int velocityX, int velocityY) {
direction = GalleryLayoutManager.LAYOUT_START;
edge = helper.getDecoratedStart(centerView);
}
float offset = (helper.getTotalSpace() + childSize * direction) / 2.f;
final int diff = (int) (offset - edge);
dist -= diff * direction;
dist -= ((int) ((helper.getTotalSpace() + childSize * direction) / 2.f) - edge) * direction;
if (orientation == LinearLayout.HORIZONTAL) {
smoothScrollBy(dist * direction, 0);
return true;
Expand Down
Loading

0 comments on commit 260362d

Please sign in to comment.