当有两个recyclerview的时候不能显示数据
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/flow" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" /> <android.support.v7.widget.RecyclerView android:id="@+id/flow1" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" /> </LinearLayout> 当有两个recyclerview都需要流式布局,并且把宽度设置为自适应,会有一个不能显示。
这里如果要测试多个recyclerView同时使用的话,需要定死recyclerView的高度了,因为在FlowLayoutManager的测量里面: if (heightMode == View.MeasureSpec.EXACTLY) { height = measureHeight; Log.d("TAG", "规则的"); } else { //以实际屏高为标准 Log.d("TAG", "不规则的");//这里就去 int contentHeight = ((Activity) context).findViewById(android.R.id.content).getHeight(); height = Math.min(totalHeight + getPaddingTop() + getPaddingBottom(), contentHeight); } setMeasuredDimension(width, height); 上面的recyclerView得到的高度是整个android.R.id.content的高度,也就是父容器高度了,所以上面的recyclerView撑满整个屏幕,自然下面那个recyclerView不会显示了。你可以去我写的viewgroup版本的流式布局:https://github.com/1002326270xc/FlowView-master