【发布时间】:2017-06-23 12:09:26
【问题描述】:
在我的应用程序中,我有 RecyclerView(线性、垂直)。在一个单元格中,我有另一个 RecyclerView(horizontal, linear)。
问题是父RecyclerView 在开始活动时向下滚动到子RecyclerView,因为带有子RecyclerView 的单元格在屏幕上可见(它的顶部,而不是整个)并且RecyclerView 必须加载它,并且加载时向下滚动以显示子回收器。
我想禁用此滚动并将父 RecyclerView 的顶部放置在活动屏幕的顶部。 RecyclerView 中是否有执行此操作的选项?
我正在尝试使用参数
app:focusableInTouchMode="@{false}"
为父母或孩子或两者兼而有之。
app:nestedScrollingEnabled="@{false}"
给孩子
app:preserveFocusAfterLayout="@{false}"
给孩子
这些都对我没有帮助
带有父回收器的布局
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical">
<com.the100am.app.widget.view.Header
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navClick="@{OnClickListeners.onBackPressed}"
app:navIcon="@{@drawable/ic_back}"
app:title="@{@string/company_details}" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/background_rounded_corners_4_dp_almost_white"
app:flip_animation_in="@{vm.needFlipIn}"
app:flip_animation_out="@{vm.needFlipOut}"
app:itemBinding="@{vm.binding}"
app:items="@{vm.rows}"
app:layoutManager="@{LayoutManagers.linear()}"
app:listener="@{vm.animatorListener}" />
</LinearLayout>
带有子回收器的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/contact_info_divider_background">
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="@dimen/divder_height"
android:background="@color/high_mid_blue"
app:visible="@{!dividersHidden}" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="16dp"
app:focusableInTouchMode="@{false}"
app:itemBinding="@{info.binding}"
app:items="@{info.fields}"
app:layoutManager="@{LayoutManagers.linear(LinearLayoutManager.HORIZONTAL, false)}"
app:nestedScrollingEnabled="@{false}"
app:preserveFocusAfterLayout="@{false}"
app:visible="@{info.fields.size > 0}" />
<View
android:id="@+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="@dimen/divder_height"
android:layout_gravity="bottom"
android:background="@color/high_mid_blue"
app:visible="@{!dividersHidden}" />
</FrameLayout>
更新:
在下面的评论中,我附上了当前的布局配置:
父 RecyclerView 布局
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="vertical">
<com.the100am.app.widget.view.Header
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:buttonClick="@{vm.getHeaderButtonClick()}"
app:buttonIcon="@{vm.getHeaderButton()}"
app:navClick="@{vm.onBack}"
app:navIcon="@{@drawable/ic_back}"
app:subtitle="@{@string/activity_contact_info_subtitle_prestring(DateManager.ago(vm.data))}"
app:title="@{@string/activity_contact_info_title}" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/background_rounded_corners_4_dp_almost_white"
app:itemBinding="@{vm.binding}"
app:items="@{vm.rows}"
app:layoutManager="@{LayoutManagers.linear()}"
/>
<FrameLayout
android:id="@+id/options_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</LinearLayout>
<data>
<variable
name="vm"
type="com.the100am.app.viewmodel.info.InfoViewModel" />
<import type="me.tatarka.bindingcollectionadapter2.LayoutManagers" />
<import type="com.the100am.app.core.DateManager" />
<import type="com.the100am.app.binding.OnClickListeners" />
</data>
</layout>
子 RecyclerView 布局
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="info"
type="com.the100am.app.viewmodel.info.SocInfo" />
<variable
name="dividersHidden"
type="boolean" />
<variable
name="snapHelper"
type="android.support.v7.widget.LinearSnapHelper" />
<import type="me.tatarka.bindingcollectionadapter2.LayoutManagers" />
<import type="android.support.v7.widget.LinearLayoutManager" />
</data>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/contact_info_divider_background">
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="@color/high_mid_blue"
app:visible="@{!dividersHidden}" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="16dp"
app:focusableInTouchMode="@{false}"
app:itemBinding="@{info.binding}"
app:items="@{info.fields}"
app:layoutManager="@{LayoutManagers.linear(LinearLayoutManager.HORIZONTAL, false)}"
app:nestedScrollingEnabled="@{false}"
app:visible="@{info.fields.size > 0}" />
<View
android:id="@+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_gravity="bottom"
android:background="@color/high_mid_blue"
app:visible="@{!dividersHidden}" />
</FrameLayout>
</layout>
【问题讨论】:
-
嘿,你有想过这个吗?我在 NestedScrollViews 中遇到了与 RecyclerViews 相同的问题。
-
@MikeOscarEcho 我不记得(绝对:))我是如何解决这个问题的,但我现在将使用当前布局配置更新我的问题。
-
@MikeOscarEcho 现在可以使用了
标签: android scroll android-recyclerview