在折叠操作栏搜索时,recyclerview将移至屏幕底部

时间:2015-08-15 17:14:20

标签: android android-recyclerview android-design-library androiddesignsupport

所以问题是,

当Actionbar搜索项目扩展时,recyclerview似乎是正确的但是当我点击搜索项目上的后退按钮时它会崩溃并且recyclelerview会自动移动到屏幕底部,如下图所示

屏幕1:当我点击操作栏的搜索项目

enter image description here

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

enter image description here

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

enter image description here

我正在使用以下库

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'  

我正在使用以下片段布局 clinic_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来解决此问题,但我想在滚动时显示滚动条,因此我无法将其删除。

请帮帮忙,谢谢

0 个答案:

没有答案