Coordinator Layout + AppBarLayout + NestedScrollView pits above Android 6.0: recyclerView displays only one line

Keywords: Android REST xml encoding

(It's a little nervous to write a blog for the first time)

The theme of AS: ScrollActivity is used to make the card interface.

Using Coordinator Layout + AppBarLayout + NestedScrollView for the official MD design was really good, and when I tested it on Android 5.1, there was no problem at all. When I tested with Android 8.1, there was a bug. Recycler View could only display one line, click fab, and not display the rest of the information at all. The logcat also reported some strange errors, which were not found by stack overflow, and the errors on Android 6.0 and 8.1 were different.

8.1 error log:

09-02 13:25:21.910 32556-32556/com.example.roy.recyclerviewdemo E/SchedPolicy: set_timerslack_ns write failed: Operation not permitted

(This error should be caused by this bug)

No more nonsense, the solution is:

NestedScrollView layouts can't use a recyclerView directly (only in this complex layout), and they also need to nest a layout in the middle tier (pro-test ConstraintLayout is available, as follows).

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">
<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.example.roy.recyclerviewdemo.EmptyRecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/item_content_margin"
        android:nestedScrollingEnabled="false"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>

The interface before and after modification is as follows:

                                      

Next comes the nonsense link:

After unsuccessful searches for each error or even some warn, I began to sort out errors one by one:

When I click the button, the Logcat will display the data added in recyclerView, but not in the view.

When I don't use ScrollActivity layout (NestedScrollView is a recyclerView directly in activity), I use the original code to find that the recyclerView display is normal.

When I had not solved the bug with all my efforts, I chose to give up. Don't use good-looking MD design. Next, when I went around the pit, I found many activities of this design when I was studying and trying to do projects by myself. I thought that they could achieve it. I was sure that my solution was in the wrong direction. So I started to look up the data and see the blog, basically using the following two methods to solve the problem of recyclerView showing only one line of data and sliding smoothly.

android:layout_height="wrap_content"
​​​​​​​android:nestedScrollingEnabled="false"

After reading many blogs, I found that NestedScrollView, which is similar to my complex head layout, is not a simple layout, so I thought, try nesting a layout, and the result is, hahaha.

What I found interesting was that the layout of the design before the change was as follows:

This is what happens when the bug is fixed:

I've also used a recyclerView directly in other types of header layouts, all the way back, and I guess it's Coordinator Layout's problem.

In this regard, my first detailed record of the filling of the blog is finished, I hope you can correct.

Posted by stanleybb on Fri, 21 Dec 2018 05:24:04 -0800