@@ -58,6 +58,8 @@ public class DragSlopLayout extends FrameLayout {
58
58
private int mFixHeight ;
59
59
// 最大高度
60
60
private int mMaxHeight ;
61
+ // 折叠系数,1.0最大表示完全折叠,mMainView 视图不动;效果同 CollapsingToolbarLayout
62
+ private float mCollapseParallax = 1.0f ;
61
63
// 整个布局高度
62
64
private int mHeight ;
63
65
// 拖拽模式的临界Top值
@@ -125,6 +127,7 @@ private void _init(Context context, AttributeSet attrs) {
125
127
TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .DragSlopLayout , 0 , 0 );
126
128
mFixHeight = a .getDimensionPixelOffset (R .styleable .DragSlopLayout_fix_height , mFixHeight );
127
129
mMaxHeight = a .getDimensionPixelOffset (R .styleable .DragSlopLayout_max_height , 0 );
130
+ mCollapseParallax = a .getFloat (R .styleable .DragSlopLayout_collapse_parallax , 1.0f );
128
131
mMode = a .getInt (R .styleable .DragSlopLayout_mode , MODE_DRAG );
129
132
a .recycle ();
130
133
if (mMode == MODE_DRAG ) {
@@ -217,7 +220,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
217
220
childView .layout (lp .leftMargin , childTop , lp .leftMargin + childWidth , childTop + childHeight );
218
221
219
222
mCriticalTop = b - (childHeight - mFixHeight ) / 2 - mFixHeight ;
220
- // mCriticalTop = b - childHeight / 2;
221
223
mExpandedTop = b - childHeight ;
222
224
mCollapsedTop = b - mFixHeight ;
223
225
}
@@ -502,6 +504,8 @@ private void _hideDragView(float percent, int curTop) {
502
504
final int dy = y - mDragView .getTop ();
503
505
if (dy != 0 ) {
504
506
ViewCompat .offsetTopAndBottom (mDragView , dy );
507
+ final float dragPercent = (mCollapsedTop - mDragView .getTop ()) * 1.0f / (mCollapsedTop - mExpandedTop );
508
+ _dragPositionChanged (mHeight - mDragView .getTop (), dragPercent );
505
509
}
506
510
}
507
511
}
@@ -555,6 +559,9 @@ private void _dragPositionChanged(int visibleHeight, float percent) {
555
559
mBlurDrawable.setAlpha((int) (percent * 255));
556
560
}
557
561
*/
562
+ if (visibleHeight >= 0 ) {
563
+ ViewCompat .setTranslationY (mMainView , -visibleHeight * (1 - mCollapseParallax ));
564
+ }
558
565
}
559
566
560
567
/*********************************** ScrollView ********************************************/
0 commit comments