阻止在开始

时间:2017-06-23 12:09:26

标签: android scroll android-recyclerview

在我的应用中,我有RecyclerView(线性,垂直)。在一个单元格中,我有另一个RecyclerViewhorizontallinear)。

问题是父RecyclerView向下滚动到初始活动的子RecyclerView,因为屏幕上RecyclerView的小组可见(顶部,而不是整个)RecyclerView 1}}必须加载它,并向下滚动以在加载时显示子回收器。

我想禁用此滚动功能,并将父级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>

Child 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>

1 个答案:

答案 0 :(得分:0)

尝试这种方式..在xml文件中输入这两行用于recylerview

{{1}}