HDL_Widget Android和iOS精简版的库,去掉高德SDK,和iOS裁剪方法
JLChen
2021-01-08 07a4e46efd0d180f881a9761c6f737e5d1c47848
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.hdl.widget.CoverFlowViewPager;
 
import android.support.v4.view.ViewPager;
import android.view.View;
 
/**
 * Created by JLChen on 2019/8/26
 */
public class CoverTransformer implements ViewPager.PageTransformer {
 
    public static final String TAG = "CoverTransformer";
 
    public static final float SCALE_MIN = 0.3f;
    public static final float SCALE_MAX = 1f;
    public static final float MARGIN_MIN = 0f;
    public static final float MARGIN_MAX = 50f;
    public float scale  = 0f;
 
    private float pagerMargin = 0f;
    private float spaceValue = 0f;
    private float rotationX    = 0f;
    private float rotationY    = 0f;
 
    public CoverTransformer(float scale, float pagerMargin, float spaceValue, float rotationY) {
        this.scale = scale;
        this.pagerMargin = pagerMargin;
        this.spaceValue  = spaceValue;
        this.rotationY   = rotationY;
    }
 
    @Override
    public void transformPage(View page, float position) {
 
//        Log.d(TAG,"position:"+position);
 
 
        if(rotationY != 0){
            float realRotationY = Math.min(rotationY,Math.abs(position * rotationY));
            page.setRotationY(position < 0f ? realRotationY : - realRotationY);
        }
 
        if (scale != 0f) {
            float realScale = getFloat(1 - Math.abs(position * scale), SCALE_MIN, SCALE_MAX);
            page.setScaleX(realScale);
            page.setScaleY(realScale);
        }
 
        if (pagerMargin != 0) {
 
            float realPagerMargin = position * (pagerMargin);
 
            if (spaceValue != 0) {
                float realSpaceValue = getFloat(Math.abs(position * spaceValue),MARGIN_MIN,MARGIN_MAX);
                realPagerMargin += (position > 0) ? realSpaceValue : - realSpaceValue;
            }
 
            page.setTranslationX(realPagerMargin);
        }
 
    }
 
    private static float getFloat(float value,float minValue,float maxValue){
        return Math.min(maxValue, Math.max(minValue, value));
    }
 
}