How can I place two components in ScrollView, one being a cardView and other a recyclerView

Viewed 15

I am new to android and trying to make a profile section of a social media app. The profile section is a fragment and inside this I wanted to have a CardView to hold user's information and then a RecyclerView to show user's posts. I have tried implementing this using a ScrollView and putting insinde the cardView and RecyclerView. I wanted both cardView and RecyclerView to be scroll as one, but currently the cardView is at its place and only elements in recyclerView are scrolling.

EDIT NestedScrollView kind of worked for me. But I also wanted overScrollMode to work fine while scrolling to the end.


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.profile.ProfileFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <com.google.android.material.card.MaterialCardView
            style="?attr/materialCardViewFilledStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp">

                    <androidx.cardview.widget.CardView
                        android:layout_width="120dp"
                        android:layout_height="120dp"
                        app:cardCornerRadius="100dp">

                        <ImageView
                            android:id="@+id/profileDisplayPicture"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:contentDescription="@string/user_profile_picture"
                            android:scaleType="centerCrop" />

                    </androidx.cardview.widget.CardView>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_margin="10dp"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/profileName"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

                        <TextView
                            android:id="@+id/profileCollegeInfo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
                    </LinearLayout>

                </LinearLayout>

                <com.google.android.material.divider.MaterialDivider
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal">


                    <ImageView
                        android:id="@+id/profileLinkedinBtn"
                        android:layout_width="36dp"
                        android:layout_height="36dp"
                        android:layout_margin="10dp"
                        android:contentDescription="@string/linkedin"
                        android:src="@drawable/ic_linkedin" />

                    <ImageView
                        android:id="@+id/profileMailBtn"
                        android:layout_width="36dp"
                        android:layout_height="36dp"
                        android:layout_margin="10dp"
                        android:contentDescription="@string/mail"
                        android:src="@drawable/ic_gmail" />

                </LinearLayout>


            </LinearLayout>


        </com.google.android.material.card.MaterialCardView>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/profileRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

</ScrollView>
0 Answers
Related