Skip to content

Commit c903dae

Browse files
committed
抽取背景模糊功能,添加折叠系数属性
1 parent 9930bf7 commit c903dae

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

dragsloplayout/src/main/java/com/dl7/drag/DragSlopLayout.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public class DragSlopLayout extends FrameLayout {
5858
private int mFixHeight;
5959
// 最大高度
6060
private int mMaxHeight;
61+
// 折叠系数,1.0最大表示完全折叠,mMainView 视图不动;效果同 CollapsingToolbarLayout
62+
private float mCollapseParallax = 1.0f;
6163
// 整个布局高度
6264
private int mHeight;
6365
// 拖拽模式的临界Top值
@@ -125,6 +127,7 @@ private void _init(Context context, AttributeSet attrs) {
125127
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DragSlopLayout, 0, 0);
126128
mFixHeight = a.getDimensionPixelOffset(R.styleable.DragSlopLayout_fix_height, mFixHeight);
127129
mMaxHeight = a.getDimensionPixelOffset(R.styleable.DragSlopLayout_max_height, 0);
130+
mCollapseParallax = a.getFloat(R.styleable.DragSlopLayout_collapse_parallax, 1.0f);
128131
mMode = a.getInt(R.styleable.DragSlopLayout_mode, MODE_DRAG);
129132
a.recycle();
130133
if (mMode == MODE_DRAG) {
@@ -217,7 +220,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
217220
childView.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight);
218221

219222
mCriticalTop = b - (childHeight - mFixHeight) / 2 - mFixHeight;
220-
// mCriticalTop = b - childHeight / 2;
221223
mExpandedTop = b - childHeight;
222224
mCollapsedTop = b - mFixHeight;
223225
}
@@ -502,6 +504,8 @@ private void _hideDragView(float percent, int curTop) {
502504
final int dy = y - mDragView.getTop();
503505
if (dy != 0) {
504506
ViewCompat.offsetTopAndBottom(mDragView, dy);
507+
final float dragPercent = (mCollapsedTop - mDragView.getTop()) * 1.0f / (mCollapsedTop - mExpandedTop);
508+
_dragPositionChanged(mHeight - mDragView.getTop(), dragPercent);
505509
}
506510
}
507511
}
@@ -555,6 +559,9 @@ private void _dragPositionChanged(int visibleHeight, float percent) {
555559
mBlurDrawable.setAlpha((int) (percent * 255));
556560
}
557561
*/
562+
if (visibleHeight >= 0) {
563+
ViewCompat.setTranslationY(mMainView, -visibleHeight * (1 - mCollapseParallax));
564+
}
558565
}
559566

560567
/*********************************** ScrollView ********************************************/

dragsloplayout/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<declare-styleable name="DragSlopLayout">
55
<attr name="fix_height" format="dimension"/>
66
<attr name="max_height" format="dimension"/>
7+
<attr name="collapse_parallax" format="float"/>
78
<attr name="mode" format="enum">
89
<enum name="drag" value="1"/>
910
<enum name="animate" value="2"/>

simple/src/main/res/layout/activity_drag_outside.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
android:layout_height="match_parent"
99
android:background="@android:color/black"
1010
app:mode="drag_outside"
11+
app:collapse_parallax="0.7"
1112
tools:context="com.dl7.simple.drag.activity.DragOutsideActivity">
1213

1314
<android.support.v4.view.ViewPager

0 commit comments

Comments
 (0)