遇到scrollview和recycleview时的冲突解决方法
来源:互联网 发布:java web license 编辑:程序博客网 时间:2024/05/17 08:46
GridGridLayoutManager
package ico.ico.widget.recycler;import android.content.Context;import android.support.v7.widget.GridLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.View;/** * Created by ICO on 2016/4/7 0007. */public class AdaptiveGridLayoutManager extends GridLayoutManager { protected int mBorderWidth = 0; public AdaptiveGridLayoutManager(Context context, int spanCount, int borderWidth) { super(context, spanCount); this.mBorderWidth = borderWidth; } public AdaptiveGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout, int borderWidth) { super(context, spanCount, orientation, reverseLayout); this.mBorderWidth = borderWidth; } @Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { int itemCount = state.getItemCount(); if (itemCount == 0) { super.onMeasure(recycler, state, widthSpec, heightSpec); return; } //计算行数 int rowCount = 1; if (itemCount > getSpanCount()) { rowCount = itemCount % getSpanCount() > 0 ? itemCount / getSpanCount() + 1 : itemCount / getSpanCount(); } View view = recycler.getViewForPosition(0); if (view != null) { measureChild(view, widthSpec, heightSpec); int measuredWidth = View.MeasureSpec.getSize(widthSpec); int measuredHeight = view.getMeasuredHeight(); setMeasuredDimension(measuredWidth, measuredHeight * rowCount + mBorderWidth * (rowCount - 1)); } super.onMeasure(recycler, state, widthSpec, heightSpec); }}
LinearLayoutManager
package ico.ico.widget.recycler;import android.content.Context;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.util.AttributeSet;import android.view.View;/** * Created by ICO on 2016/4/7 0007. */public class AdaptiveLinearLayoutManager extends LinearLayoutManager { protected int mBorderWidth = 0; public AdaptiveLinearLayoutManager(Context context, int borderWidth) { super(context); this.mBorderWidth = borderWidth; } public AdaptiveLinearLayoutManager(Context context, int orientation, boolean reverseLayout, int borderWidth) { super(context, orientation, reverseLayout); this.mBorderWidth = borderWidth; } public AdaptiveLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int borderWidth) { super(context, attrs, defStyleAttr, defStyleRes); this.mBorderWidth = borderWidth; } @Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { int expandSpec = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST); heightSpec = expandSpec; super.onMeasure(recycler, state, widthSpec, heightSpec);// int itemCount = getItemCount();// if (itemCount == 0) {// super.onMeasure(recycler, state, widthSpec, heightSpec);// return;// }// int rowCount = itemCount / getSpanCount() + 1;// View view = recycler.getViewForPosition(0);// if (view != null) {// measureChild(view, widthSpec, heightSpec);// int measuredWidth = View.MeasureSpec.getSize(widthSpec);// int measuredHeight = view.getMeasuredHeight();// setMeasuredDimension(measuredWidth, measuredHeight * rowCount + mBorderWidth * (rowCount - 1));// } }}
瀑布流的还没想过,希望大神们指点
0 0
- 遇到scrollview和recycleview时的冲突解决方法
- 完美解决因scrollview和recycleview引起的滑动冲突
- scrollview嵌套recycleview冲突的问题3
- ScrollView和ListView套用冲突的解决方法
- 安卓中ScrollView和ListView冲突的解决方法
- Fragment和scrollview事件冲突的解决方法
- bottomsheetbehavior和recycleview的冲突
- 以上三篇重写recycleview 和 scrollview 冲突问题 在5.0手机上的问题 4
- swipRefreshLayout 和Scrollview 以及recycleView嵌套产生滑动冲突问题解决
- scrollview与recycleview冲突解决
- 工作中遇到ListView和ScrollView的冲突
- 解决Scrollview嵌套recycleview的显示不完全,滑动冲突问题
- scrollview中嵌套recycleview冲突的问题 1
- scrollview嵌套recycleview滑动冲突的问题之2
- Scrollview 嵌套listView 与recycleView 滑动冲突的解决
- [Android]ScrollView和ListView套用冲突的解决方法
- 当ScrollView手势和super view手势冲突的解决方法
- Android 中listview 和scrollview 滚动冲突事件的解决方法
- C++ hdoj 2035 (人见人爱A^B)
- hdu 5839 Special Tetrahedron
- jQuery表单对象属性过滤选择器
- HDU 5832 A water problem
- HDU 5842 Lweb and String(水题)
- 遇到scrollview和recycleview时的冲突解决方法
- 堆和栈的区别(详细)
- 渲染流程
- 多目录时Makefile 的编写方法
- Ajax验证登陆
- 【BestCoder Round #59 (div.1) B】疯狂的火神
- 三分算法
- 使用Xutils框架中的HttpRequest.HttpMethod出现Error:(45, 31) 错误: 无法访问HttpRequestBase
- LightOJ 1097 - Lucky Number(线段树)