I have a fragment xml in a TabLayout. The TabLayout is in a CollapsingToolbar layout which collapses when scrolling the content of the Fragments in the TabLayout down. I have one fragment where I need a TextView above a recyclerView.
If I have the layout as below taken from this question I asked before:
<LinearLayout>
<NestedScrollView
<TextView>
</TextView>
</NestedScrollView>
<View>
</View>
<RecyclerView>
</RecyclerView>
</LinearLayout>
It works ok, until the TextView has so much content in that it fills or takes up most of the screen, the RecyclerView ends up using the remaining space in the view to be displayed:
|------------------| |<TextView-------->| |<---------------->| |<---------------->| |<---------------->| |<---------------->| |</TextView------->| |<RecyclerView---->| |</RecyclerView--->| |__________________|
So the recyclerview is left with minimal space to be viewed. If the Textview takes up the whole screen, the recyclerView just doesn't display.
Taken from this SO Question If the layout is:
<FrameLayout>
<NestedScrollView
<TextView>
</TextView>
</NestedScrollView>
<View>
</View>
<RecyclerView>
</RecyclerView>
</FrameLayout>
Only the recyclerView displays and the TextView is just nonexistent.
If the Layout is:
<NestedScrollView>
<LinearLayout
<TextView>
</TextView>
<View>
</View>
<RecyclerView>
</RecyclerView>
</LinearLayout>
</NestedScrollView>
The TextView just shows, whether there is content in the RecyclerView or not.
How can I have the TextView scroll out the window enough to reveal the recyclerview so the screen can go from this:
|------------------| |<TextView-------->| |<---------------->| |<---------------->| |<---------------->| |<---------------->| |</TextView------->| |<RecyclerView---->| |</RecyclerView--->| |__________________|
to this:
|------------------| |<---------------->| |</TextView------->| |<RecyclerView---->| |<---------------->| |<---------------->| |<---------------->| |<---------------->| |</RecyclerView--->| |__________________|
My current XML code where only the RecyclerView shows and not the 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>