So the problem is,
When Actionbar searchitem expands recyclerview appears to be correct but as i click back button on searchitem it collapse and recyclerview moves to bottom of screen automatically as shown in below images
Screen 1: When i click on search item of actionbar
Screen 2: When i click on back button of search item
Screen 3: When i try to scroll recyclerview it moves automatically to bottom
I am using following libraries
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'
I am using following fragment layout 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>
My onCreateView() method of fragment class
@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;
}
My activity layout:
<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>
Please Note :
This problem can be solved by removing android:scrollbars="vertical"
from RecyclerView
but i want to show scrollbar on scroll hence i can not remove it.
Please help out and thanks
This was a known bug that should be fixed. Try upgrading to:
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'