2

Here's my layout.

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/activity_main_swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_marginBottom="45dp"
        android:layout_height="wrap_content">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true">

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp"
                android:id="@+id/noob_button"
                android:text="haha" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/noob_button"
                android:orientation="vertical"
                android:clipToPadding="false"
                android:scrollbars="vertical" />
        </RelativeLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

This is all inside RelativeLayout.

I have set recyclerview.setNestedScrol..(false);

It still hangs and if I set fixed height of the RecyclerView it doesn't hang. It scrolls but the scroll is not smooth.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
danlero
  • 41
  • 4

1 Answers1

0

You do not actually need a RecyclerView inside a NestedScrollView. As far as I have understood your question, you need a Button and a RecyclerView under the button. So you might consider adding the Button as the header of the RecyclerView which is neater implementation.

If you are thinking of adding a header in your RecyclerView please see my answer here on how this can be achieved.

I have explained how a footer can be added. The same rule applies for adding a header view as well. Please let me know if you have any further questions regarding this.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • If i put it as a header it will be occupying the first row of the recyclerview and i won't be able to manage the data coming from api in recyclerview – danlero Feb 11 '18 at 10:07
  • Surely you can manage the data received from your API. You need to handle the login inside your `onBindViewHolder`. It would be great if you could help us to understand the scenario that you are having. So that we could help more specifically. – Reaz Murshed Feb 11 '18 at 16:36
  • The recyclerview is being filled from data which i get from api so if i put a header that means the header will occupy the first row of the recyclerview so the data on the first position of the json array will be beneath of the header. – danlero Feb 12 '18 at 05:24
  • The means header will overlap the first data, if i set data from second position then on every api call the header will repeat. I just wanted the view(Textview, viewpager) to be above the recyclerview and don't have any relation with the recycler but scrolls when we scroll recyclerview so i used the nestedcrollview but it causes lags. I am thinking to set the appropriate data in the api i.e the required data on first position. – danlero Feb 12 '18 at 05:24
  • Nope. Neither the header will repeat each time you call the API not it will overlap the first data. I think you have misunderstood the idea of having a header of a `RecyclerView`. The header can have a custom layout as well. Please follow the implementation of adding a header in you `RecyclerView` first. You will have the idea. – Reaz Murshed Feb 12 '18 at 05:31