[英]How to expand recycleview height inside viewpager2
我有一個包含 2 個片段的 viewpager2。 兩個片段都包含一個回收視圖,並顯示 4 個項目(第一個片段)和 5 個項目(第二個片段)的列表。 我遇到的問題是,我的對話框片段(具有 viewpager2)沒有擴展到第二個片段的完整所需高度。 因此,我無法看到我的第二個片段 recycleview 的每個元素,必須向下滾動才能看到最后一個元素。
如何更改對話框片段的高度以查看第二個/具有最多項目的片段的每個項目。 我希望 viewpager2 的高度與包含最多項目的片段的高度相同。 目前,它是相反的。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/color_primary_dark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/shop_filter_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/emptyView" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/shop_filter_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="24dp"
app:layout_constraintBottom_toTopOf="@+id/btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/shop_filter_tablayout" />
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/color_shop_filter_btn_background"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/shop_filter_submit_filter"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="@string/shop_filter_submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/shop_filter_dismiss_filter"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/shop_filter_delete"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/shop_filter_submit_filter"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.MaterialToolbar>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_shop_filter"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/shop_filter_list_item" />
<ProgressBar
android:id="@+id/shop_filter_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="invisible" />
</androidx.constraintlayout.widget.ConstraintLayout>
我有幾個想法:
嘗試“強制”更改對話框片段的高度。 類似的東西: 如何設置 DialogFragment 的寬度和高度?
嘗試將 SecondFragmet 的回收站視圖高度設置為我們項目的 5xheigh。
如果總是有 5 個項目,不要使用回收站視圖?? ;)
如果其中任何一個有用,請給我一個信號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.