【问题标题】:how to reset the NavigationView scroll position如何重置 NavigationView 滚动位置
【发布时间】:2017-05-03 07:08:23
【问题描述】:

我有如下导航视图,

<android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        style="@style/NavDrawer"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:itemBackground="@android:color/transparent"
        app:itemTextColor="@color/drawer_item">

        <ExpandableListView
            android:id="@+id/list_navigation_menu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/list_view_marigin_top"
            android:divider="@android:color/transparent"
            android:dividerHeight="@dimen/list_view_divider_height"
            android:fitsSystemWindows="true"
            android:listSelector="@android:color/transparent"
            android:visibility="gone" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/list_view_marigin_top"
            android:fitsSystemWindows="true" />
    </android.support.design.widget.NavigationView>

如何让 NavigationView 在打开时始终从其“原始”滚动位置开始,这样第一个菜单项始终可见,无论之前滚动位置在哪里。

我尝试了以下 3 行/解决方案,但没有成功:

  ((NavigationMenuView)((NavigationView)mViewHolder.mNavigationView).getChildAt(0)).scrollToPosition(0);

    mViewHolder.mNavigationView.scrollTo(0,0);

    mViewHolder.mNavigationView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_DEFAULT);

【问题讨论】:

    标签: android navigation-drawer drawerlayout


    【解决方案1】:

    这个解决方案对我有用 RecyclerView.getLayoutManager().scrollToPosition(0);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 2013-10-29
      相关资源
      最近更新 更多