NestedScrollview + TextView + RecyclerView

I have an xml snippet in TabLayout. TabLayout is located in the CollapsingToolbar layout, which collapses when scrolling the contents of fragments in TabLayout down. I have one snippet where I need a TextView over a recyclerView.

If I have a layout as shown below, this question I asked before :

<LinearLayout> <NestedScrollView <TextView> </TextView> </NestedScrollView> <View> </View> <RecyclerView> </RecyclerView> </LinearLayout> 

It works fine, until the TextView has so much content that it fills or occupies most of the screen, the RecyclerView ends up using the remaining space in the displayed view:

 |------------------| |<TextView-------->| |<---------------->| |<---------------->| |<---------------->| |<---------------->| |</TextView------->| |<RecyclerView---->| |</RecyclerView--->| |__________________| 

In this way, recyclerview stays with minimal viewing space. If the Textview is full screen, recyclerView just doesnโ€™t appear.

Taken from this QUESTION ... If the layout:

 <FrameLayout> <NestedScrollView <TextView> </TextView> </NestedScrollView> <View> </View> <RecyclerView> </RecyclerView> </FrameLayout> 

Only recyclerView screens are displayed, and the TextView is simply missing.

If the layout:

 <NestedScrollView> <LinearLayout <TextView> </TextView> <View> </View> <RecyclerView> </RecyclerView> </LinearLayout> </NestedScrollView> 

TextView simply shows if there is content in RecyclerView or not.

How can I scroll the TextView window enough to show recyclerview so the screen can jump from this:

 |------------------| |<TextView-------->| |<---------------->| |<---------------->| |<---------------->| |<---------------->| |</TextView------->| |<RecyclerView---->| |</RecyclerView--->| |__________________| 

:

 |------------------| |<---------------->| |</TextView------->| |<RecyclerView---->| |<---------------->| |<---------------->| |<---------------->| |<---------------->| |</RecyclerView--->| |__________________| 

My current XML is where only RecyclerView is displayed, not TextView:

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:id="@+id/item_shipping_shipping_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="start|left" android:padding="@dimen/margin_16" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </android.support.v4.widget.NestedScrollView> <View android:id="@+id/line43" android:layout_width="match_parent" android:layout_height="@dimen/line_height" android:background="@color/light_gray" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/item_shipping_fragment_recyclerview" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </FrameLayout> 
+6
source share
4 answers

The only fix I had for my problem was to make the list a programmatic attachment in a nested scrollView. I could not use RecyclerView and nestedScrollview together.

+1
source

Try adding weight for both layouts.
For example, if you want the TextView part to be less than or equal to the RecyclerView part:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/item_shipping_shipping_description" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="start|left" android:padding="@dimen/margin_16"/> </android.support.v4.widget.NestedScrollView> <View android:id="@+id/line43" android:layout_width="match_parent" android:layout_height="@dimen/line_height" android:background="@color/light_gray"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/item_shipping_fragment_recyclerview" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout> 

Thus, the TextView layout containing the layout will know that it should wrap the content on one side, but with the same weight that RecyclerView has, and it will select the smallest of them.

+6
source

Instead of arranging the frame, take a vertical orientation linearlayout and put the recyclerview in another linearlayout:

 <LinearLayout orientation=verticle > <LinearLayout > <android.support.v4.widget.NestedScrollView> <TextView/> </android.support.v4.widget.NestedScrollView> <View /> </LinearLayout> <LinearLayout> <android.support.v7.widget.RecyclerView/> </LinearLayout> </LinearLayout> 

Layout height as child layout should be set to wrap_content

0
source

You can use CoordinatorLayout to hide the TextView on the scrollbar of the ReciclerView:

Here is an easy tutorial.

0
source

All Articles