Adding header view to recyclerview with gridlayout manager Android Adding header view to recyclerview with gridlayout manager: To add a header to a recyclerview with a gridlayout, first the adapter needs to be told that the header view is the first position - rather than the standard cell used for the content. Next, the layout manager must be told that the first position should have a span equal to the *span count of the entire list. Take a regular RecyclerView.Adapter class and configure it as follows: The same approach can be used add a footer in addition to or instead of a header.
Posts
Item OffsetDecoration Item OffsetDecoration for GridLayoutManager in RecycleView. Following example will help to give equal space to an item in GridLayout. Item OffsetDecoration for GridLayoutManager in RecycleView. Following example will help to give equal space to an item in GridLayout. ItemOffsetDecoration.java public class ItemOffsetDecoration extends RecyclerView.ItemDecoration { private int mItemOffset; private int spanCount = 2; public ItemOffsetDecoration(int itemOffset) { mItemOffset = itemOffset; } public ItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) { this(context.getResources().getDimensionPixelSize(itemOffsetId)); } @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int position = parent.getChildLayoutPosition(view); GridLayoutManager manager = (GridLayoutManager) p...
Step 1: build.gradle compile 'com.android.support:cardview-v7:26+' compile 'com.android.support:recyclerview-v7:26.+' Step 2: main_activity.xml <? xml version= "1.0" encoding= "utf-8" ?> < RelativeLayout 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 :layout_width= "match_parent" android :layout_height= "match_parent" tools :context= "csdevbin.arham.recyclerviewdemo.MainActivity" > < android.support.v7.widget.RecyclerView android :id= "@+id/my_recycler_view" android :layout_width= "match_parent" android :layout_height= "match_parent" ...