RecyclerView方法onCreateViewHolder()和onBindViewHolder()没有调用

来源:互联网 发布:仿淘宝省市地区级联 编辑:程序博客网 时间:2024/06/07 09:58


原因:至今小编都未知,初步分析为

android.support.constraint.ConstraintLayout有bug


打印log getItemCount() > 0

RecyclerViewAdapter 构造方法执行了

RecyclerView 基本的都设置了,还是不行。

最后只能修改布局文件,去掉布局文件中的外层包裹


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        xmlns:tools="http://schemas.android.com/tools"        android:layout_width="match_parent"        android:layout_height="match_parent">          <LinearLayout    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="end|bottom"    android:orientation="vertical">    <android.support.design.widget.FloatingActionButton        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="@dimen/fab_margin"        android:src="@drawable/to_top22"        />    </LinearLayout>        </android.support.constraint.ConstraintLayout>



数据不显示时的布局文件

<?xml version="1.0" encoding="utf-8"?>    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        xmlns:tools="http://schemas.android.com/tools"        android:layout_width="match_parent"        android:layout_height="match_parent">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <include                layout="@layout/toolbar"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_gravity="top" />            <LinearLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:background="@color/white"                android:clickable="true"                android:orientation="vertical">                <android.support.v4.widget.SwipeRefreshLayout                    android:layout_width="match_parent"                    android:layout_height="match_parent">                    <android.support.v7.widget.RecyclerView                        android:layout_width="match_parent"                        android:layout_height="match_parent" />        </android.support.v4.widget.SwipeRefreshLayout>        </LinearLayout>        </LinearLayout>    <LinearLayout    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="end|bottom"    android:orientation="vertical">    <android.support.design.widget.FloatingActionButton        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="@dimen/fab_margin"        android:src="@drawable/to_top22"        />    </LinearLayout>        </android.support.constraint.ConstraintLayout>



阅读全文
0 0
原创粉丝点击