gridlayoutmanager
How to make RecyclerView scroll smoothly?
Add this wherever you have declared RecyclerView in your Activity or Fragment RecyclerView mRecyclerview = (RecyclerView) findViewById(…); mRecyclerview.setNestedScrollingEnabled(false); setNestedScrollview(false) does the work for you.
RecyclerView GridLayoutManager with full width header
Try with this: mLayoutManager = new GridLayoutManager(this, 2); mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch(mAdapter.getItemViewType(position)){ case MyAdapter.HEADER: return 2; case MyAdapter.ITEM: default: return 1; } } }); And check these links: RecyclerView: Grid with header Set span for items in GridLayoutManager using SpanSizeLookup
How to set the height of an item row in GridLayoutManager
When inflating layout for your views in adapter, you can set their height programmatically. In order to evaluate proper height to use you can rely on parent ViewGroup (that is the RecyclerView itself). Here it is a sample: @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = mLayoutInflater.inflate(R.layout.view_item, parent, false); // work here … Read more
android – how to catch Drop action of ItemTouchHelper which is used with RecyclerView
While dragging and dropping an item, the onMove() can be called more than once, but the clearView() will be called once. So you can use this to indicate the drag was over(drop was happened). And use two variables dragFrom and dragTo to trace the really position in a completed “drag & drop”. private ItemTouchHelper.Callback dragCallback … Read more
Drag and drop items in RecyclerView with GridLayoutManager
There is actually a better way to achieve this. You can use some of the RecyclerView‘s “companion” classes: ItemTouchHelper, which is a utility class to add swipe to dismiss and drag & drop support to RecyclerView. and its ItemTouchHelper.Callback, which is the contract between ItemTouchHelper and your application // Create an `ItemTouchHelper` and attach it … Read more
RecyclerView 2 Columns with CardView
Extracted required info from the accepted answer in case URL becomes invalid in future and to save time. GridLayoutManager is used to display the RecyclerView in Grid manner instead of list. RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 2); recyclerView.setLayoutManager(mLayoutManager); Kotlin version: recyclerView.apply { layoutManager = GridLayoutManager(this, 2) }
(Smooth)ScrollToPosition doesn’t work properly with RecyclerView
Finally I was able to make it work! LinearLayoutManager.scrollToPositionWithOffset(int, int) did the trick.
How to center RecyclerView items horizontally with vertical GridLayoutManager
Try letting the column item fill the width of the column while centering everything inside: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”180dp” android:orientation=”vertical” android:padding=”4dp”> <ImageView android:id=”@+id/movie_column_photo” android:layout_width=”80dp” android:layout_height=”120dp” android:layout_gravity=”center_horizontal”/> <TextView android:id=”@+id/movie_column_title” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center”/> </LinearLayout>
Square layout on GridLayoutManager for RecyclerView
To have the square elements in my RecyclerView, I provide a simple wrapper for my root View element; I use the following SquareRelativeLayout in place of RelativeLayout. package net.simplyadvanced.widget; import android.content.Context; import android.util.AttributeSet; import android.widget.RelativeLayout; /** A RelativeLayout that will always be square — same width and height, * where the height is based off … Read more