0

Details:

Dependency: (latest)

implementation 'com.android.support:recyclerview-v7:27.0.2' 

XML:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bg_gray"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginEnd="@dimen/marginTwenty" android:layout_marginStart="@dimen/marginTwenty" android:layout_marginTop="@dimen/marginTen" android:orientation="vertical"> <LinearLayout android:id="@+id/contactLoadingLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" android:padding="@dimen/marginThirty"> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/waitText" android:textAlignment="center" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/contactsLayoutView" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/mobileView" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="@dimen/marginTwenty" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_mobile" /> <TextView android:id="@+id/txtMobileNumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/mobileNumber" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/mobileRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:scaleType="fitXY" /> <TextView android:id="@+id/txtNoMobileData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddMobile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/emailView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/marginTen" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="18dp" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_email" /> <TextView android:id="@+id/txtEmailNumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/email" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/emailRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:scaleType="fitXY" /> <TextView android:id="@+id/txtNoEmailData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddEmail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/facebookView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/marginTen" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="@dimen/marginTwenty" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_facebook" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/facebookHint" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/facebookRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:scaleType="fitXY" /> <TextView android:id="@+id/txtNoFacebookData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddFacebook" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/linkedInView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/marginTen" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="@dimen/marginTwenty" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_linkedi" /> <TextView android:id="@+id/txtLinkedIn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/linkedInHint" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/linkedInRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:scaleType="fitXY" /> <TextView android:id="@+id/txtNoLinkedInData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddLinkedIn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/twitterView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/marginTen" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="@dimen/marginTwenty" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_twitter" /> <TextView android:id="@+id/txtTwitter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/twitterHint" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/twitterRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:scaleType="fitXY" /> <TextView android:id="@+id/txtNoTwitterData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddTwitter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/youtubeView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/marginTen" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="@dimen/marginTwenty" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_youtube" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/youtubeHint" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/youtubeRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:adjustViewBounds="true" android:scaleType="fitXY" /> <TextView android:id="@+id/txtNoYoutubeData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddYoutube" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/gitHubView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/marginTwenty" android:layout_marginTop="@dimen/marginTen" android:background="@drawable/curved_background_white" android:orientation="vertical" android:padding="@dimen/marginTen"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="@dimen/marginTwenty" android:layout_height="@dimen/marginTwenty" android:layout_gravity="center_vertical" android:layout_marginEnd="5dp" android:contentDescription="@string/dummyContent" android:src="@drawable/ic_github" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitXY" android:text="@string/gitHubHint" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/githubRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" /> <TextView android:id="@+id/txtNoGitHubData" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="@dimen/marginTen" android:text="@string/no_contact_found" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" android:visibility="gone" /> <TextView android:id="@+id/btnAddGithub" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/add" android:textColor="@color/colorPrimary" android:textSize="@dimen/textSize_18sp" android:textStyle="bold" /> </LinearLayout> </LinearLayout> <include android:id="@+id/noInternetLayoutContact" layout="@layout/no_internet_layout" android:visibility="gone" /> </LinearLayout> </ScrollView> 

JAVA Code:

youtubeRecyclerView.setLayoutManager(new LinearLayoutManager(getActContext(), LinearLayoutManager.VERTICAL, false)); youtubeRecyclerView.setHasFixedSize(true); youtubeRecyclerView.setItemAnimator(new DefaultItemAnimator()); youtubeRecyclerView.setAdapter(attributeAdapter); youtubeRecyclerView.setVisibility(View.VISIBLE); 

Note:

  • i have 6 recycler views in single activity and out of those 6 any one of the recycler view becomes scrollable and rest works fine (wrap_content) based on screen size.
  • My Parent View is ScrollView.

I have done enough research on internet and stackoverflow, couldn't find the solution, So asked question here. Please don't mark as duplicate.

10
  • android:adjustViewBounds="true" android:scaleType="fitXY" are properties of imageView Commented Mar 6, 2018 at 12:32
  • Please post whole your xml file. It is hard to understand what would you like to get ;) Commented Mar 6, 2018 at 12:33
  • My recyclerview was without those properties, I tried that just experiment it didn't worked out. Commented Mar 6, 2018 at 12:33
  • @muminers, added whole XML file code. Commented Mar 6, 2018 at 12:36
  • try this solution Commented Mar 6, 2018 at 12:38

3 Answers 3

0

Try wrapping RecyclerView using fixed height parent

You can go for a fixed height or wrap_content for LinearLayout parent

 <LinearLayout android:id="@+id/llRecyclerContainer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/marginTen"> <android.support.v7.widget.RecyclerView android:id="@+id/facebookRecyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> 

In your java file :

facebookRecyclerView.setHasFixedSize(true); 
Sign up to request clarification or add additional context in comments.

4 Comments

In this case what if the size is small? like 2 items? in that case it will have empty white space, which will make the UI look bad
RecyclerView will get scrolled in this fixed area you are wrapping
That was my question bro. I gave recyclerview wrapcontent height, but it is becoming scrollable when the list length increases 3 which i dont want. I want to set height of my all 6 recyclerview scrollable even if the list size increases 3.
Please check my question. i already gave youtubeRecyclerView.setHasFixedSize(true);
0

It's not good practice to use RecycylerView inside scrollView as result it won't support recycling if views.

Better use one vertical parent RecyclerView and based on view type add your child RecyclerView to parent.

Comments

0

I managed to resolve this issue by putting my recyclerview in a nestedscrollview and kept 'android:nestedScrollingEnabled' disabled/false.

1 Comment

Placing a recycler view inside a nested scroll view disables view recycling and therefore defeats the purpose of using a recyclerview. If you have a large list of data this will all be drawn at create time and would cause the main thread to lag.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.