我瀏覽過很多帖子,但無法獲得我需要的帖子。我有一個帶有RecyclerView的LinearLayout,我希望兩者都可以滾動。現在,LinearLayout是固定的,RecyclerView是唯一可以滾動的。我嘗試了nestedscrollview,但無法使其工作。出於某種原因,recyclerview.adapter使用nestedscrollview分解。任何想法? BTW:我在Xamarin開發AndroidLinearLayout和RecyclerView不會一起滾動
這是我的佈局
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</LinearLayout>
<FrameLayout
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
然後,我在其中佈局是FrameLayout里加載一個片段:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/spinner"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresher"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
這是一個標題,但考慮到我的解決方案,創建標題視圖不是最好的主意r爲recyclerview。我使用LinearLayout來組織視圖。語義上是一個標題。您是否建議將LinearLayout更改爲其他佈局? –
這取決於。當您滾動時,您是否希望標題消失?或者你想讓它永遠在場?您是否希望頁腳只在滾動到底部時出現?你可以保持LinearLayout *不帶* ScrollView,在那裏插入標題,並且只有第二個元素是RecyclerView(它會自己滾動)。 爲什麼定義Header ViewHolders不是您理想的解決方案? – themarshal
假設我希望它像第一個項目。我不希望它消失,只是爲了頂部。定義標題ViewHolders並不理想,因爲recyclerview是我在其他視圖中使用的組件,其他視圖中我不需要標題。如果您不知道解決方案,這很複雜,但請相信我,最好將其分開。我沒有頁腳,只有標題。我不明白你給我的解決方案,你有一個例子/教程嗎?謝謝! –