RecyclerView has data but not displayed (analysis in many cases)

There are several situations where RecyclerView has data but does not display it. There are the following points:

1. In the initialization code of recycleview, whether to set LayoutManager (recyclerView.setLayoutManager).

2. After getting the data, the notifyDataSetChanged() method is not called to refresh the data.

3. LayoutInflater.from(context).inflate(R.layout.item_first_page, parent, false) under the onCreateViewHolder() method in Adapter

The layout file that loads the layout statement is not the actual layout file to be used due to copying or other reasons, and the data cannot be mapped to the layout file through the ViewHolder, but this problem does not report an error.

4. In the layout file, match_parent is used for the width (or height) of RecyclerView, but the properties of View Top and Botom in the corresponding item layout are unreasonably set, resulting in incomplete or non-display of the content.

5. The corresponding width (or height) of RecyclerView uses match_parent, and the attributes of View Top and Botom in the corresponding item layout are set fine, but there is a problem with the width and height settings of the parent layout, resulting in the width or height of RecyclerView being only 0dp (match_parent Take 0dp but adapt according to elastic constraints).

(It usually occurs when ConstraintLayout nests ConstraintLayout, even if the parent layout of the child ConstraintLayout is not ConstraintLayout, but the root layout is ConstraintLayout, this problem may also occur)

   Supplement: When match_parent is selected, the effect previewed by Android Studio is the actual display effect of the app, which is different from wrap_content.

6. The width (or height) corresponding to RecyclerView uses wrap_content,

The content of the last column of RecyclerView is not fully displayed

layout_height uses wrap_content and should be changed to match_parent.

7. Android RecyclerView mutual nested inner layer RecyclerView display incomplete problem, the solution please see Android RecyclerView mutual nested inner layer RecyclerView display incomplete problem_recyclerview nested recyclerview display incomplete_ErwinNakajima's blog-CSDN blog

If you have any questions about this, please contact qq1164688204.

Recommend Android open source projects

Project function introduction: RxJava2 and Retrofit2 projects, add automatic token management function, add RxJava2 life cycle management, use App architecture design is MVP mode and MVVM mode, use componentization at the same time, part of the code uses Kotlin, this project is under continuous maintenance.

Project address: https://gitee.com/urasaki/RxJava2AndRetrofit2

Guess you like

Origin blog.csdn.net/NakajimaFN/article/details/130955249