我有一个带有ViewPager的RecyclerView,而后者又有另一个recyclerView。 ViewPager中的recyclerView不会加载全部项目,而只会加载其中的一个,并且不会滚动以显示其余项目
我试图用wrap_content设置两个回收站视图的layout_height,并且也将其嵌套在nestedSCrollView内,但是没有成功。
// First outside recyclerview
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
// cell item with viewPager
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="50dp" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
// recyclerView inside viewPager
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
我希望外部的recyclerView可以填充整个项目的高度,而不是内部的recyclerview接缝不会加载整个项目,而是屏幕上唯一可见的没有滚动的接缝。
编辑
fragment__events_detail(布局)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_marginBottom="@dimen/toolbar__height"
tools:layout_marginTop="@dimen/actionbar__height">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
回收站视图的第一个单元格
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical">
<!-- img video club -->
<ImageView
android:id="@+id/imgVideoClub"
android:layout_width="0dp"
android:layout_height="300dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars[12]" />
<!-- play icon -->
<ImageView
android:id="@+id/playIcon"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/play_icon" />
<LinearLayout
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/btn_rounded_orange_outline_red_bg"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView8"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
app:srcCompat="@drawable/prohibition_icon" />
<TextView
android:text="Segnala abuso"
android:textColor="#fff"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
第二个具有TabLayout和ViewPager的单元格
<?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:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="50dp" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
viewPager第一个选项卡中的片段,其中包含recyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:layout_marginBottom="@dimen/toolbar__height"
tools:layout_marginTop="@dimen/actionbar__height">
<!-- header -->
<TextView
android:text="Eventi"
style="@style/header_txtStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- separator -->
<View
android:background="@color/separator_background"
android:layout_width="wrap_content"
android:layout_height="1dp"/>
<!-- container events search -->
<LinearLayout
android:orientation="horizontal"
android:paddingLeft="@dimen/main__horizzontalPadding"
android:paddingRight="@dimen/main__horizzontalPadding"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- search icon -->
<ImageView
android:src="@drawable/search_icon"
android:layout_width="20dp"
android:layout_height="30dp" />
<EditText
android:id="@+id/events__home_eventsSearchEditTxt"
android:background="@android:color/transparent"
android:layout_marginLeft="16dp"
android:hint="Cerca eventi"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- separator -->
<View
android:background="@color/separator_background"
android:layout_width="wrap_content"
android:layout_height="3dp"/>
<!-- range time events -->
<androidx.constraintlayout.widget.ConstraintLayout
android:paddingLeft="@dimen/main__horizzontalPadding"
android:paddingRight="@dimen/main__horizzontalPadding"
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="@+id/events__home_thisWeekTimeTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Questa settimana"
android:textColor="@color/events__home_itemNotSelected"
android:gravity="center"
android:textSize="@dimen/events__home_rangeTimeTxtSize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/events__home_nextWeekTimeTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Prossima settimana"
android:textColor="@color/events__home_itemNotSelected"
android:textSize="@dimen/events__home_rangeTimeTxtSize"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@id/events__home_calendarRangeTimeContainer"
app:layout_constraintLeft_toRightOf="@id/events__home_thisWeekTimeTxt"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/events__home_calendarRangeTimeContainer"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="@+id/events__home_calendarRangeTimeTxt"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="@dimen/events__home_rangeTimeTxtSize"
android:textColor="@color/events__home_itemNotSelected"
android:gravity="center" />
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:padding="5dp"
android:scaleType="centerCrop"
android:src="@drawable/calendar__icon" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
第二个回收站视图的项目
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/row__events_home_container"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:background="@drawable/event__background_rounded"
android:padding="20dp">
<ImageView
android:id="@+id/calendarIcon"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/clockIcon"
app:layout_constraintEnd_toEndOf="@+id/clockIcon"
app:layout_constraintStart_toStartOf="@+id/clockIcon"
app:srcCompat="@drawable/calendar__icon" />
<TextView
android:id="@+id/row__events_home_dateEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="TextView"
android:textColor="@color/events__home_secondaryTextColor"
app:layout_constraintBottom_toBottomOf="@+id/calendarIcon"
app:layout_constraintStart_toEndOf="@+id/calendarIcon"
app:layout_constraintTop_toTopOf="@+id/calendarIcon" />
<TextView
android:id="@+id/row__events_home_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/row__events_home_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="@color/colorPrimary"
app:layout_constraintStart_toStartOf="@+id/row__events_home_title"
app:layout_constraintTop_toBottomOf="@+id/row__events_home_title" />
<ImageView
android:id="@+id/locationIcon"
android:layout_width="0dp"
android:layout_height="30dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/location__icon" />
<TextView
android:id="@+id/row__events_home_locationEventName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="TextView"
android:textColor="@color/events__home_secondaryTextColor"
app:layout_constraintBottom_toBottomOf="@+id/locationIcon"
app:layout_constraintStart_toEndOf="@+id/locationIcon"
app:layout_constraintTop_toTopOf="@+id/locationIcon" />
<ImageView
android:id="@+id/clockIcon"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:layout_constraintBottom_toTopOf="@+id/locationIcon"
app:layout_constraintEnd_toEndOf="@+id/locationIcon"
app:layout_constraintStart_toStartOf="@+id/locationIcon"
app:srcCompat="@drawable/clock__icon" />
<TextView
android:id="@+id/row__events_home_timeEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="TextView"
android:textColor="@color/events__home_secondaryTextColor"
app:layout_constraintBottom_toBottomOf="@+id/clockIcon"
app:layout_constraintStart_toEndOf="@+id/clockIcon"
app:layout_constraintTop_toTopOf="@+id/clockIcon" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/row__events_home_interestBtn"
android:layout_width="130dp"
android:layout_height="30dp"
android:background="@drawable/btn_rounded_orange_outline"
android:paddingLeft="10dp"
android:paddingRight="20dp"
app:layout_constraintBottom_toBottomOf="@+id/clockIcon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/clockIcon">
<ImageView
android:id="@+id/imageView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/interest__events_icon" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Mi interessa"
android:textColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/row__events_home_buyBtn"
android:layout_width="130dp"
android:layout_height="30dp"
android:background="@drawable/btn_rounded_orange_outline"
android:paddingLeft="10dp"
android:paddingRight="20dp"
app:layout_constraintBottom_toBottomOf="@+id/locationIcon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/locationIcon">
<TextView
android:id="@+id/textView9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Prenota"
android:textColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView11"
app:layout_constraintTop_toTopOf="parent"
tools:text="Prenota" />
<ImageView
android:id="@+id/imageView11"
android:layout_width="20dp"
android:layout_height="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ticket__events_buy" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>