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.
android:adjustViewBounds="true" android:scaleType="fitXY"are properties of imageView