比较常用的效果,有现成的,如此甚好!:)
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.Scroller;
import com.snail.labaffinity.R;
import com.snail.labaffinity.adapter.SlideFragmentPagerAdapter;
/**
* 1 ViewPager+TabLayout as content
* 2 FragmentTabHost+Fragment as content
* 3 bug :can not assertain which View is inTouch
*/
public class DragScrollDetailsLayout extends LinearLayout {
public interface OnSlideFinishListener {
void onStatueChanged(CurrentTargetIndex status);
}
public enum CurrentTargetIndex {
UPSTAIRS,
DOWNSTAIRS;
public static CurrentTargetIndex valueOf(int index) {
return 1 == index ? DOWNSTAIRS : UPSTAIRS;
}
}
private static final float DEFAULT_PERCENT = 0.3f;
private static final int DEFAULT_DURATION = 400;
private int mMaxFlingVelocity;
private int mMiniFlingVelocity;
private int mDefaultPanel = 0;
private int mDuration = DEFAULT_DURATION;
private float mTouchSlop;
private float mDownMotionY;
private float mDownMotionX;
private float mInitialInterceptY;
public void setPercent(float percent) {
mPercent = percent;
}
private float mPercent = DEFAULT_PERCENT;
/**
* flag for listview or scrollview ,if child overscrolled ,do not judge view region 滚过头了,还是可以滚动
*/
private boolean mChildHasScrolled;
private View mUpstairsView;
private View mDownstairsView;
private View mCurrentTargetView;
private Scroller mScroller;
private VelocityTracker mVelocityTracker;
private OnSlideFinishListener mOnSlideDetailsListener;
private CurrentTargetIndex mCurrentViewIndex = CurrentTargetIndex.UPSTAIRS;
public DragScrollDetailsLayout(Context context) {
this(context, null);
}
public DragScrollDetailsLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DragScrollDetailsLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DragScrollDetailsLayout, defStyleAttr, 0);
mPercent = a.getFloat(R.styleable.DragScrollDetailsLayout_percent, DEFAULT_PERCENT);
mDuration = a.getInt(R.styleable.DragScrollDetailsLayout_duration, DEFAULT_DURATION);
mDefaultPanel = a.getInt(R.styleable.DragScrollDetails