Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ScrollableLayout/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.scrollablelayout.simple"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
Expand Down Expand Up @@ -75,9 +76,12 @@ private void initView() {

iv_spit.setVisibility(View.GONE);
tv_title.setTranslationY(-1000);
sl_root.setDamping(true);
sl_root.computeScroll();
sl_root.setOnScrollListener(new ScrollableLayout.OnScrollListener() {
@Override
public void onScroll(int translationY, int maxY) {
Log.d("onScroll",translationY+"/"+maxY);
translationY = -translationY;
if (titleMaxScrollHeight == 0) {
titleMaxScrollHeight = ((View) tv_title.getParent()).getBottom() - tv_title.getTop();
Expand All @@ -99,13 +103,18 @@ public void onScroll(int translationY, int maxY) {
} else {
iv_spit.setVisibility(View.GONE);
}
if (-translationY < hearderMaxHeight) {
iv_avatar.setScaleX((hearderMaxHeight+translationY)/hearderMaxHeight);
iv_avatar.setScaleY((hearderMaxHeight+translationY)/hearderMaxHeight);
}

iv_spit.getBackground().setAlpha(alpha);

tv_title.setTranslationY(Math.max(0, maxScrollHeight + translationY));
}
});

pfl_root.setPullToRefresh(false);
pfl_root.setEnabledNextPtrAtOnce(true);
pfl_root.setLastUpdateTimeRelateObject(this);
pfl_root.setPtrHandler(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:id="@+id/iv_avatar_alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_alignBottom="@+id/iv_avatar"
android:layout_alignLeft="@+id/iv_avatar"
android:layout_alignRight="@+id/iv_avatar"
Expand Down
3 changes: 1 addition & 2 deletions ScrollableLayout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.android.tools.build:gradle:2.3.0-beta4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions ScrollableLayout/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Apr 11 12:52:13 CST 2016
#Sat Feb 18 02:24:10 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
5 changes: 2 additions & 3 deletions ScrollableLayout/library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.w446108264'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 11
Expand All @@ -22,5 +21,5 @@ android {
}

dependencies {
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class ScrollableLayout extends LinearLayout {

private int mCurY;
private boolean isClickHead;
private boolean isDamping;
private int mScrollMinY = 10;

enum DIRECTION {
Expand All @@ -76,7 +77,9 @@ public ScrollableHelper getHelper() {
return mHelper;
}

public ScrollableLayout(Context context) { this(context, null); }
public ScrollableLayout(Context context) {
this(context, null);
}

public ScrollableLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
Expand All @@ -98,7 +101,7 @@ public ScrollableLayout(Context context, AttributeSet attrs, int defStyleAttr) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mHeadView = getChildAt(0);
if(mHeadView != null){
if (mHeadView != null) {
measureChildWithMargins(mHeadView, widthMeasureSpec, 0, MeasureSpec.UNSPECIFIED, 0);
maxY = mHeadView.getMeasuredHeight();
mHeadHeight = mHeadView.getMeasuredHeight();
Expand Down Expand Up @@ -184,6 +187,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
}
break;
case MotionEvent.ACTION_UP:
checkDamping();
if (flag2 && shiftY > shiftX && shiftY > mTouchSlop) {
mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
float yVelocity = -mVelocityTracker.getYVelocity();
Expand Down Expand Up @@ -249,9 +253,10 @@ public void computeScroll() {
}
} else {
if (mHelper.isTop()) {
int deltaY = (currY - mLastScrollerY);
/* int deltaY = (currY - mLastScrollerY);
int toY = getScrollY() + deltaY;
scrollTo(0, toY);
scrollTo(0, toY);*/
checkDamping();
if (mCurY <= minY) {
mScroller.forceFinished(true);
return;
Expand Down Expand Up @@ -311,6 +316,27 @@ private void recycleVelocityTracker() {
}
}


private void checkDamping() {
if(isDamping){
if (isClickHead || !isSticked()) {
if (maxY / 2 < mCurY) {
scrollTo(0, mHeadHeight);
} else {
scrollTo(0, 0);
}
}
}
}

public boolean isDamping() {
return isDamping;
}

public void setDamping(boolean damping) {
isDamping = damping;
}

private void checkIsClickHead(int downY, int headHeight, int scrollY) {
isClickHead = downY + scrollY <= headHeight;
}
Expand Down