嘿伙计我对android编程有点新意,但我似乎无法在我的viewpager工作中获取我的回收视图。 我正在使用带有tablayout的viewpager并在其中一个页面中,我有一个recyclerview,其中包含每个内部动态创建内容的cardviews(每个卡片视图将根据内部内容具有不同的高度)。 我现在遇到的问题是我的recycleriew的高度只延伸到viewpager的高度,即使有时我的recyclerview里面的cardview有太多内容不适合viewpager屏幕。
正如你从图片中看到的那样,我的cardview占据了整个屏幕,但我在我的练习列表中还有一些练习,我曾用它来创建cardview,它们被切断了..
下面是我的包含我的视图寻呼机的活动的xml,viewpager片段的xml,以及我的cardview的xml
我的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>带有recyclerview的viewpager片段
<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>在recyclerview内的cardview
<?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>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.
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>最满意答案
消除CardView周围的外部LinearLayout 。
它有android:layout_height="match_parent"导致你的问题,它只有CardView作为孩子,所以它没有必要。
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.
更多推荐
发布评论