viewpager中的Recyclerview只扩展了viewpager的长度(Recyclerview inside viewpager only extends the length of the

编程入门 行业动态 更新时间:2024-10-28 18:25:36
viewpager中的Recyclerview只扩展了viewpager的长度(Recyclerview inside viewpager only extends the length of the viewpager)

嘿伙计我对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.

更多推荐

本文发布于:2023-07-24 00:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:长度   Recyclerview   viewpager   extends   length

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!