我浏览过很多帖子,但无法获得我需要的帖子。我有一个带有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是我在其他视图中使用的组件,其他视图中我不需要标题。如果您不知道解决方案,这很复杂,但请相信我,最好将其分开。我没有页脚,只有标题。我不明白你给我的解决方案,你有一个例子/教程吗?谢谢! –