【发布时间】:2016-03-05 05:52:47
【问题描述】:
我在 ScrollView 中有一个 RecyclerView。当我尝试滚动到底部时,RecyclerView(child element) 在父级开始滚动之前滚动到底部。但我想要的是,父母应该在孩子开始滚动之前完全滚动。这是我的布局文件。有人可以指导我如何实现这一目标吗?
<RelativeLayout 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">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/user_activity_linear_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/blank_layout"
android:orientation="vertical">
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recently_watched_recycler_view"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/blank_layout"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
【问题讨论】:
-
我觉得我应该警告你,在滚动视图中滚动视图几乎总是会给你带来 android 问题,应该不惜一切代价避免
-
我已经阅读了很多针对滚动视图内的滚动视图的此类警告。为什么它被认为是一种不好的做法?我的用例要求我有这样的布局。
-
如果上面是你的实际布局,为什么不把
blank_layout作为recycler 视图的第一项呢?这当然假设您希望回收器视图填充滚动视图,根据您提供的 xml,它看起来就像您所做的那样。如果不是这样,为什么它必须首先在滚动视图中? -
实际上我的实际布局有一个寻呼机,并且寻呼机的每一页都有 recyclerview 作为其子级。 (为了简单起见,我在这里删除了寻呼机并用 recyclerview 替换)现在,我没有将 recyclerview 内的空白空间作为第一个孩子,因为那样 PagerTabStrip 和 recyclerview 孩子之间会有空白空间。我希望这个空白空间位于 PagerTabStrip 上方。有什么建议吗?
-
那么,如果你只想要标签条上方的空间,那为什么还需要滚动视图呢?
标签: android android-recyclerview android-scrollview