David Yuan
David Yuan

Reputation: 820

Recyclerview inside viewpager only extends the length of the viewpager

Hey guys I am a bit new to android programming but I can't seem to get my recycle view inside my viewpager working. I am using my viewpager with a tablayout and inside one of the pages, I have a recyclerview which contains cardviews with dynamically created content inside each of them (each card view will have different heights based on the content inside). The issue I am having right now is that my recycleriew's height only extends to the height of the viewpager even tho sometimes the cardview inside my recyclerview has too much content to fit on the viewpager screen.

Example

As you can see from the picture, my cardview has taken up the whole screen but I have a few more exercises in my exercise list that I used to created the cardview and they are cut off..

Below is my xml for the activity that contains my view pager, the xml for the viewpager fragment, and also the xml for my cardview

Activity with my viewpager

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/view"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/view">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"/>

    </android.support.design.widget.AppBarLayout>

</RelativeLayout>

viewpager fragment with the recyclerview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.davidyuan7536.workoutlog.LogFragment"
    android:orientation="vertical">

                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/homeFeedRecycleView" />

</LinearLayout>

cardview inside the recyclerview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="16dp"
    >

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cv"
        >

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

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:background="@color/homeFeedUserHeaderBackground">

                <ImageView
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:id="@+id/homeFeedUserAvatar"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginRight="16dp"
                    android:src="@drawable/profile_icon"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/homeFeedUserName"
                    android:layout_toRightOf="@+id/homeFeedUserAvatar"
                    android:layout_alignParentTop="true"
                    android:textSize="20sp"
                    android:text="User Name"
                    android:singleLine="true"
                    android:ellipsize="end"
                    android:layout_marginRight="10dp"
                    android:textColor="@color/textColorPrimary"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/homeFeedWorkoutTitle"
                    android:layout_toRightOf="@+id/homeFeedUserAvatar"
                    android:layout_below="@+id/homeFeedUserName"
                    android:text="Workout Titile"
                    android:layout_marginTop="10dp"
                    android:layout_marginRight="10dp"
                    android:textSize="15sp"
                    android:textColor="@color/textColorPrimary"/>

            </RelativeLayout>



            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/homeFeedExercisesContainer"
                android:paddingBottom="10dp">



            </LinearLayout>

        </LinearLayout>
    </android.support.v7.widget.CardView>

</LinearLayout>

Upvotes: 0

Views: 1357

Answers (1)

kris larson
kris larson

Reputation: 30985

Eliminate the outer LinearLayout surrounding the CardView.

It has android:layout_height="match_parent" which is causing your problem, and it only has the CardView as a child, so it's not necessary anyways.

Upvotes: 1

Related Questions