2 回答

TA貢獻1884條經驗 獲得超4個贊
用于NestedScrollView使整個視圖可滾動
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
tools:context=".Activity"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/gradient_background">
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<View
android:id="@+id/lineView"
android:layout_width="30dp"
android:layout_height="0.5dp"
android:background="@drawable/divider_line"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_toEndOf="@id/lineView"
android:layout_margin="8dp"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

TA貢獻1851條經驗 獲得超5個贊
我可以讓RelativeLayout不透明,以便RecyclerView項目滾動到它的“后面”嗎?
只需將約束布局更改為線性布局即可。
我如何才能使整個布局與 RecyclerView 一起滾動?
邏輯:為此,您必須在要擴充 RecyclerView 內容的 XML 文件中包含相對布局?,F在,每次都會正確地膨脹相對布局。
因此,為了克服這個問題,無論您在 RecyclerView 構造函數中傳遞什么,都需要一個標志/計數,僅當計數等于零/設置標志時以及當計數大于 0 或設置標志時才膨脹相對布局,然后隱藏相對布局。
這樣,相對布局就會隨 RecyclerView 內容一起滾動,并且僅膨脹一次。
添加回答
舉報