Skip to content

Commit

Permalink
修复计算距离中心精度问题
Browse files Browse the repository at this point in the history
  • Loading branch information
crazysunj committed Nov 7, 2020
1 parent cd875f6 commit 30c2411
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README_2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static Bitmap convertReflection(@NonNull Bitmap originalImage, int viewWi
## gradle依赖

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

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':cardslideview')
implementation 'com.crazysunj:cardslideview:2.2.0'
// implementation project(':cardslideview')
implementation 'com.crazysunj:cardslideview:2.2.1'
// 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
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.0'
publishVersion = '2.2.1'
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 @@ -431,7 +431,7 @@ private void firstFillBottom(RecyclerView.Recycler recycler, int position, int i
* @return 计算距离中心轴偏移百分比
*/
private float calculateOffsetPercentToCenter(View child, float offset) {
final float distance = calculateDistanceToCenter(child, offset);
final int distance = calculateDistanceToCenter(child, offset);
final OrientationHelper helper = getOrientationHelper();
final int size = helper.getDecoratedMeasurement(child) + itemMargin;
return distance * 1.f / size;
Expand All @@ -442,10 +442,10 @@ private float calculateOffsetPercentToCenter(View child, float offset) {
* @param offset view的滑动偏移量
* @return 返回view距离中心轴的距离
*/
private float calculateDistanceToCenter(View child, float offset) {
private int calculateDistanceToCenter(View child, float offset) {
final OrientationHelper helper = getOrientationHelper();
final float centerToStart = helper.getTotalSpace() / 2.f + helper.getStartAfterPadding();
return helper.getDecoratedMeasurement(child) / 2.f + helper.getDecoratedStart(child) - centerToStart - offset;
return (int) (helper.getDecoratedMeasurement(child) / 2.f + helper.getDecoratedStart(child) - centerToStart - offset + 0.5f);
}

private int getHorizontalSpace() {
Expand Down Expand Up @@ -1050,7 +1050,7 @@ boolean snapToTargetExistingView() {
if (centerView == null) {
return false;
}
int distanceToCenter = (int) calculateDistanceToCenter(centerView, 0);
int distanceToCenter = calculateDistanceToCenter(centerView, 0);
boolean isIntercept = distanceToCenter != 0;
if (isIntercept) {
if (mOrientation == LinearLayout.HORIZONTAL) {
Expand Down

0 comments on commit 30c2411

Please sign in to comment.