4

I am working on Recycler view and here i placed the three recycler views in a row horizontally in a layout.The issue is second and third recycler view items are displayed but cannot able to scroll even though using nested scroll inside and hereby attached xml.Kindly suggest me how to make scroll the second and third recycler view.

<RelativeLayout
    android:id="@+id/layout_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="220dp"
    android:background="@color/color_bottom_sheet"
    android:elevation="@dimen/z_bottom_sheet"
    app:behavior_hideable="true"
    app:behavior_peekHeight="80dp"
    app:layout_behavior="@string/string_bottom_sheet_behavior">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rightLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <LinearLayout
            android:id="@+id/lay1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#ff0000">
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewmonth"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:fillViewport="true"
            android:verticalScrollbarPosition="right">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:id="@+id/lay2"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#00ff00">
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerViewdate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
                </LinearLayout>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
        <LinearLayout
            android:id="@+id/lay3"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0000ff">
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewyear"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
    </LinearLayout>
    <TextView
        android:id="@+id/text_view_sheet_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/activity_vertical_margin"
        android:text="@string/text_pull_to_show_more"
        android:textSize="@dimen/text_size_medium"
        android:visibility="gone" />
    <TextView
        android:id="@+id/text_view_more_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_view_sheet_title"
        android:paddingLeft="@dimen/activity_vertical_margin"
        android:paddingRight="@dimen/activity_vertical_margin"
        android:text="@string/text_more_contet_to_user"
        android:textSize="@dimen/text_size_big"
        android:textStyle="bold"
        android:visibility="gone" />
    <Button
        android:id="@+id/btnclick"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/text_view_more_content"
        android:layout_marginLeft="@dimen/activity_vertical_margin"
        android:layout_marginRight="@dimen/activity_vertical_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:text="@string/text_click_me"
        android:visibility="gone" />
</RelativeLayout>

//Java

@Override
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewmonth);
   RecyclerView recyclerdate = (RecyclerView) findViewById(R.id.recyclerViewdate);
   RecyclerView recycleryear = (RecyclerView) findViewById(R.id.recyclerViewyear);
   ButterKnife.bind(this);
   LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
   LinearLayoutManager linearLayoutManagerdate = new LinearLayoutManager(getApplicationContext());
   LinearLayoutManager linearLayoutManageryear = new LinearLayoutManager(getApplicationContext());

   recyclerView.setLayoutManager(linearLayoutManager);
   recyclerdate.setLayoutManager(linearLayoutManagerdate);
   recycleryear.setLayoutManager(linearLayoutManageryear);

   recyclerView.setNestedScrollingEnabled(false);
   recyclerdate.setNestedScrollingEnabled(false);
   recycleryear.setNestedScrollingEnabled(false);

   for (int i = 0; i <= 31; i++) {
       dayList.add(String.valueOf(i));
   }
   CustomAdapter customAdapter = new CustomAdapter(MainActivity.this, monthList);
   recyclerView.setAdapter(customAdapter);


   DayAdapter dayAdapter=new DayAdapter(MainActivity.this,dayList);
   recyclerdate.setNestedScrollingEnabled(false);
   recyclerdate.setAdapter(dayAdapter);
   recyclerdate.setNestedScrollingEnabled(false);

   YearAdapter yearAdapter=new YearAdapter(MainActivity.this,monthList);
   recycleryear.setAdapter(yearAdapter);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

3 Answers3

2

Post your java code also where you are initializing the recycler views. Also, Try to remove the recycler view from the nested scroll view (you can place them without nested scroll view )

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rightLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <LinearLayout
        android:id="@+id/lay1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff0000">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerViewmonth"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
            <LinearLayout
                android:id="@+id/lay2"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#00ff00">
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerViewdate"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
    <LinearLayout
        android:id="@+id/lay3"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#0000ff">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerViewyear"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
</LinearLayout>
Tarun Kumar
  • 498
  • 5
  • 16
  • 1
    @Tarun Kumar need to scroll each section separately – Rajakumar Jul 18 '18 at 09:45
  • yes @Rajakumar, when the recycler views are placed in different linear layouts then they scroll independently. You need not to wrap them in nested scroll view. – Tarun Kumar Jul 18 '18 at 09:47
  • in the right layout give, weightsum: 3 and to layout 1,2,3 give layout weight:1 With this they'll be line up horizontally with equal space and yes @Manohari, remove the nested scroll view and check. – Tarun Kumar Jul 18 '18 at 09:49
  • @TarunKumar thanks for your reply..after implementing your suggestion I am facing the problem that lay2 recyclerview is not scrolling don't know whats wrong in that – Rajakumar Jul 18 '18 at 10:01
  • ANd what about the third recycler view? is it scrolling now? And also do check the logs is there any exception. – Tarun Kumar Jul 18 '18 at 10:12
  • @TarunKumarsure i will check log..not only second third also not scrolling – Rajakumar Jul 18 '18 at 10:15
2

Keep all the Recycler views inside the Nested Scroll View.

  • 1
    each section need to scroll seperatly – Rajakumar Jul 18 '18 at 09:43
  • if you want each recycler view to show complete data then yes this will work or else defining particular height for the recycler views will also work. In both the scenarios you have to keep all the recycler views inside the nested scroll view. –  Jul 18 '18 at 09:50
-1

Change your parent layout height to match_parent. Like

<RelativeLayout
    android:id="@+id/layout_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_bottom_sheet"
    android:elevation="@dimen/z_bottom_sheet"
    app:behavior_hideable="true"
    app:behavior_peekHeight="80dp"
    app:layout_behavior="@string/string_bottom_sheet_behavior">


</RelativeLayout>