效果图镇楼
如果我们想要完成上图所产生的效果,必须深层次的解决ScrollView嵌套ListView所产生的的滑动冲突,解决滑动冲突的最好办法就是重写底层布局的滑动监听事件,有兴趣的同学可以去看一下android开发艺术探索,对滑动冲突的解决写的比较全面。这里我们就不多赘述,五万在这里将自己重写好的底层布局分享给大家,大家直接拿去用就好了。不用谢我,点赞就好。
一,讲五万写好布局文件和适配器粘贴到你的项目中
1.DragSrollLayout(重新改写监听后的View父布局)——直接粘就行
public class DragScrollLayout 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 = 300;
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 DragScrollLayout(Context context) {
this(context, null);
}
public DragScrollLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public DragScrollLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DragScrollLayout, defStyleAttr, 0);
mPercent = a.getFloat(R.styleable.DragScrollLayout_percent, DEFAULT_PERCENT);
mDuration = a.getInt(R.styleable.DragScrollLayout_duration, DEFAULT_DURATION);
mDefaultPanel = a.getInt(R.styleable.DragScrollLayout_default_panel, 0);
a.recycle();
mScroller = new Scroller(getContext(), new DecelerateInterpolator());
mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
mMaxFlingVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity();
mMiniFlingVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity();
setOrientation(VERTICAL);
}
public void setOnSlideDetailsListener(OnSlideFinishListener listener) {
this.mOnSlideDetailsListener = listener;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
final int childCount = getChildCount();
if (1 >= childCount) {
throw new RuntimeException("SlideDetailsLayout only accept childs more than 1!!");
}
mUpstairsView = getChildAt(0);
mDownstairsView