Android NestedScrollView nested LinearLayout nested RecyclerView sub-item layout display is not complete

  • The cause is incomplete
  • Solution 1:
  • Solution 2:
  • Solution three:

March 3, 1971: Inspired by MAO Zedong’s directive “We, too, want to build a Sputnik,” China successfully launches a scientific experimental earth satellite. The satellite weighs 221 kilograms. Its orbit is 266 kilometers from the earth’s closest point, the farthest point 1826 kilometers, the orbital plane and the earth’s equatorial plane of the turtle is 69.9 degrees; It takes 106 minutes to go round the earth. It has successfully sent back various scientific experiment data to the ground with the frequency of 20009 MHZ and 19995 MHZ. The satellite is equipped with cosmic ray, X-ray, high magnetic field and heat flow detector out of orbit, making China obtain space physics data with satellite for the first time.

The cause is incomplete

Business Requirement Effect Diagram (1.1):

\

The onMeasure of the ScrollView conflicts with the onMeasure of the LinearLayout, so the LinearLayout will be calculated automatically regardless of whether the width = match_parent is set

Reference documentation

Solution 1:

From the Internet

Will use RelativeLayout RecyclerView packages, and add the android: descendantFocusability = “blocksDescendants” attribute

		 <RelativeLayout
                android:layout_width="match_parent"
                android:descendantFocusability="blocksDescendants"
                android:layout_height="wrap_content">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rel"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

            </RelativeLayout>
Copy the code

Android: descendantFocusability attribute means that when a view for focus, define the relationship between the ViewGroup and its control.

It has a total of three attribute values, which are:

  • BeforeDescendants get focus over subclass controls
  • AfterDescendants get focus only when the subclass control does not need it
  • BlocksDescendants override subclass controls to get focus directly

Solution 2:

From the Internet

Will you first in the XML layout ScrollView replaced with android. Support. The v4. Widget. NestedScrollView, and set in the Java code

recyclerView.setNestedScrollingEnabled(false);
Copy the code

Solution three:

My method

Replace the sub-item layout with a RelativeLayout instead of a LinearLayout