所以问题是

当Actionbar searchitem展开时,recyclerview看起来是正确的,但是当我在searchitem上单击后退按钮时,它会折叠,并且recyclerview会自动移至屏幕底部,如下图所示

屏幕1:当我单击动作栏的搜索项时

android - 在折叠的操作栏上,recyclerview移至屏幕底部-LMLPHP

屏幕2:当我单击搜索项目的后退按钮时

android - 在折叠的操作栏上,recyclerview移至屏幕底部-LMLPHP

屏幕3:当我尝试滚动recyclerview时,它会自动移到底部

android - 在折叠的操作栏上,recyclerview移至屏幕底部-LMLPHP

我正在使用以下库

compile 'com.android.support:appcompat-v7:22.2.0'

compile 'com.android.support:design:22.2.0'

compile 'com.android.support:recyclerview-v7:22.2.0'


我正在使用以下片段布局clipart_fragment.xml

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_recycler_view"

    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    >
    </android.support.v7.widget.RecyclerView>


我的片段类的onCreateView()方法

  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Bundle arguments = getArguments();
        int pageNumber = arguments.getInt(ARG_PAGE);
        RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_clinic,container,false);
        recyclerView.setAdapter(new YourRecyclerAdapter(getActivity()));
        recyclerView.setLayoutManager(/*new LinearLayoutManager(getActivity())*/new GridLayoutManager(getActivity(),4, LinearLayoutManager.VERTICAL,false));
        return recyclerView;
    }


我的活动布局:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways"
             />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            app:tabIndicatorColor="@color/colorPrimary"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="#EEE" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>


请注意 :

通过从android:scrollbars="vertical"删除RecyclerView可以解决此问题,但是我想在滚动条上显示滚动条,因此无法将其删除。

请帮忙,谢谢

最佳答案

这是应该修复的已知错误。尝试升级到:

compile 'com.android.support:design:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'

关于android - 在折叠的操作栏上,recyclerview移至屏幕底部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32027195/

10-12 00:23
查看更多