package xiaochen.you.meituan.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.InputDeviceCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.view.NestedScrollingParent;
import android.support.v4.view.NestedScrollingParentHelper;
import android.support.v4.view.ScrollingView;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v4.view.accessibility.AccessibilityRecordCompat;
import android.support.v4.widget.EdgeEffectCompat;
import android.support.v4.widget.ScrollerCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import java.util.List;
/**
* Created by you on 2017/3/29.
*/
public class NestedScrollView extends FrameLayout implements NestedScrollingParent,
NestedScrollingChild, ScrollingView {
/**
* 支持向下滑动偏移
*/
static final int PULLDOWN_SCALE = 2;
/**
* 向下越界滑动时的滑动比例
*/
static final int PULLDOWN_SCROLL = 3;
static final int ANIMATED_SCROLL_GAP = 250;
static final float MAX_SCROLL_FACTOR = 0.5f;
private static final String TAG = "NestedScrollView";
/**
* Interface definition for a callback to be invoked when the scroll
* X or Y positions of a view change.
*
* <p>This version of the interface works on all versions of Android, back to API v4.</p>
*
* @see #setOnScrollChangeListener(OnScrollChangeListener)
*/
public interface OnScrollChangeListener {
/**
* Called when the scroll position of a view changes.
*
* @param v The view whose scroll position has changed.
* @param scrollX Current horizontal scroll origin.
* @param scrollY Current vertical scroll origin.
* @param oldScrollX Previous horizontal scroll origin.
* @param oldScrollY Previous vertical scroll origin.
*/
void onScrollChange(NestedScrollView v, int scrollX, int scrollY,
int oldScrollX, int oldScrollY);
}
private long mLastScroll;
private final Rect mTempRect = new Rect();
private ScrollerCompat mScroller;
private EdgeEffectCompat mEdgeGlowTop;
private EdgeEffectCompat mEdgeGlowBottom;
/**
* Position of the last motion event.
*/
private int mLastMotionY;
/**
* True when the layout has changed but the traversal has not come through yet.
* Ideally the view hierarchy would keep track of this for us.
*/
private boolean mIsLayoutDirty = true;
private boolean mIsLaidOut = false;
/**
* The child to give focus to in the event that a child has requested focus while the
* layout is dirty. This prevents the scroll from being wrong if the child has not been
* laid out before requesting focus.
*/
private View mChildToScrollTo = null;
/**
* True if the user is currently dragging this ScrollView around. This is
* not the same as 'is being flinged', which can be checked by
* mScroller.isFinished() (flinging begins when the user lifts his finger).
*/
private boolean mIsBeingDragged = false;
/**
* Determines speed during touch scrolling
*/
private VelocityTracker mVelocityTracker;
/**
* When set to true, the scroll view measure its child to make it fill the currently
* visible area.
*/
private boolean mFillViewport;
/**
* Whether arrow scrolling is animated.
*/
private boolean mSmoothScrollingEnabled = true;
private int mTouchSlop;
private int mMinimumVelocity;
private int mMaximumVelocity;
/**
* ID of the active pointer. This is used to retain consistency during
* drags/flings if multiple pointers are used.
*/
private int mActivePointerId = INVALID_POINTER;
/**
* Used during scrolling to retrieve the new offset within the window.
*/
private final int[] mScrollOffset = new int[2];
private final int[] mScrollConsumed = new int[2];
private int mNestedYOffset;
/**
* Sentinel value for no current active pointer.
* Used by {@link #mActivePointerId}.
*/
private static final int INVALID_POINTER = -1;
private SavedState mSavedState;
private static final AccessibilityDelegate ACCESSIBILITY_DELEGATE = new AccessibilityDelegate();
private static final int[] SCROLLVIEW_STYLEABLE = new int[] {
android.R.attr.fillViewport
};
private final NestedScrollingParentHelper mParentHelper;
private final NestedScrollingChildHelper mChildHelper;
private float mVerticalScrollFactor;
private OnScrollChangeListener mOnScrollChangeListener;
public NestedScrollView(Context context) {
this(context, null);
}
public NestedScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public NestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initScrollView();
final TypedArray a = context.obtainStyledAttributes(
attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);
setFillViewport(a.getBoolean(0, false));
a.recycle();
mParentHelper = new NestedScrollingParentHelper(this);
mChildHelper = new NestedScrollingChildHelper(this);
// ...because why else would you be using this widget?
setNestedScrollingEnabled(true);
ViewCompat.setAccessibilityDelegate(this, ACCESSIBILITY_DELEGATE);
}
// NestedScrollingChild
@Override
public void setNestedScrollingEnabled(boolean enabled) {
mChildHelper.setNestedScrollingEnabled(enabled);
}
@Override
public boolean isNestedScrollingEnabled() {
return mChildHelper.isNestedScrollingEnabled();
}
@Override
public boolean startNestedScroll(int axes) {
return mChildHelper.startNestedScroll(axes);
}
@Override
public void stopNestedScroll() {
mChildHelper.stopNestedScroll();
}
@Override
public boolean hasNestedScrollingParent() {
return mChildHelper.hasNestedScrollingParent();
}
@Override
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,
int dyUnconsumed, int[] offsetInWindow) {
return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed,
offsetInWindow);
}
@Override
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
}
@Over
没有合适的资源?快使用搜索试试~ 我知道了~
仿美团详情滑动界面,并兼容NestedScroll嵌套 源码实例
共49个文件
png:16个
xml:14个
java:6个
5星 · 超过95%的资源 需积分: 34 335 下载量 140 浏览量
2017-05-01
22:24:08
上传
评论 5
收藏 1.16MB RAR 举报
温馨提示
仿美团详情滑动界面,并兼容NestedScroll嵌套
资源推荐
资源详情
资源评论
收起资源包目录
meituan.rar (49个子文件)
meituan
gradlew 5KB
settings.gradle 16B
gradle
wrapper
gradle-wrapper.properties 233B
gradle-wrapper.jar 52KB
local.properties 458B
gradlew.bat 2KB
gradle.properties 747B
.gitignore 127B
app
src
androidTest
java
xiaochen
you
meituan
ExampleInstrumentedTest.java 770B
test
java
xiaochen
you
meituan
ExampleUnitTest.java 414B
main
AndroidManifest.xml 679B
res
mipmap-hdpi
ic_launcher.png 3KB
mipmap-xxxhdpi
ic_launcher.png 10KB
mipmap-xhdpi
ic_launcher.png 5KB
mipmap-mdpi
ic_launcher.png 2KB
drawable
bg_scroll_select.xml 561B
layout
fragment_test2.xml 564B
activity_main_scroll.xml 5KB
activity_main_top.xml 1KB
fragment_test1.xml 556B
activity_main.xml 1KB
activity_main_include.xml 2KB
drawable-xhdpi
meituan2.png 755KB
gc_deal_second.png 905B
dp_ad_icon_star_small.png 435B
takeout_ic_new.png 672B
dp_ad_icon_half.png 629B
meituan1.png 168KB
icon_title.png 18KB
icon_descript.png 57KB
trip_oversea_icon_list_group.png 304B
icon_food.png 92KB
dp_ad_icon_star_small_gary.png 418B
values-w820dp
dimens.xml 364B
values
colors.xml 260B
strings.xml 73B
styles.xml 565B
dimens.xml 216B
color
bg_scroll_select.xml 255B
mipmap-xxhdpi
ic_launcher.png 8KB
java
xiaochen
you
meituan
TestFragment.java 1KB
widget
NestedScrollView.java 75KB
MainActivity.java 4KB
ConfigUtils.java 3KB
libs
app.iml 13KB
.gitignore 8B
build.gradle 1KB
proguard-rules.pro 661B
build.gradle 521B
共 49 条
- 1
资源评论
- a28809762017-05-04很好很实用
RangoY
- 粉丝: 45
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功