Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView autofit LayoutManager

I am using RecyclerView with StaggeredGridLayoutManager.

I want this StaggeredGridLayoutManager or whichever LayoutManager occupy empty areas if there is. For instance if I set the spanCount=3 it must occupy all screen width even I have 2 items or 1 items. In StaggeredGridLayoutManager I can full span single row by : setFullSpan(true); but can't span 2 items for only one row.

My code for RecyclerView :

StaggeredGridLayoutManager sglm= new StaggeredGridLayoutManager(spanCount,StaggeredGridLayoutManager.VERTICAL);
sglm.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);

I tried AsymmetricGridView and twoway-view but there is always an empty area

I collect some screenshots of Facebook App :

enter image description here

And here is the Google Keep App as you can see the row height is fixed for every row but the width of items is flexible and I've never seen any empty area with Google Keep:

enter image description here

And when I am using it there is always an empty area, as you can see the black part of image is empty. I want the RecyclerView should occupy that area by extending my rows like in Google Keep app:

enter image description here

I visited this page : android-how-to-create-a-facebook-like-images-gallery-grid but it didn't helped me.

Here is the another page I visited : grid-of-images-like-facebook-for-android

Is there anyone uses RecyclerView or any View like that? Can someone suggest me any way or any idea or guide me to where I must start?

like image 566
Yasin Kaçmaz Avatar asked Sep 28 '16 19:09

Yasin Kaçmaz


3 Answers

I recently saw FlexboxLayoutManager at FlexBox Layout Github.

If you want to achieve same effect as Google Keep application you can use it.

like image 191
Yasin Kaçmaz Avatar answered Nov 18 '22 07:11

Yasin Kaçmaz


/**
 * A LayoutManager that lays out children in a staggered grid formation.
 * It supports horizontal & vertical layout as well as an ability to layout children in reverse.
 * <p>
 * Staggered grids are likely to have gaps at the edges of the layout. To avoid these gaps,
 * StaggeredGridLayoutManager can offset spans independently or move items between spans. You can
 * control this behavior via {@link #setGapStrategy(int)}.
 */


/**
 * Sets the gap handling strategy for StaggeredGridLayoutManager. If the gapStrategy parameter
 * is different than the current strategy, calling this method will trigger a layout request.
 *
 * @param gapStrategy The new gap handling strategy. Should be
 *                    {@link #GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS} or {@link
 *                    #GAP_HANDLING_NONE}.
 * @see #getGapStrategy()
 */
public void setGapStrategy(int gapStrategy) {
    assertNotInLayoutOrScroll(null);
    if (gapStrategy == mGapStrategy) {
        return;
    }
    if (gapStrategy != GAP_HANDLING_NONE &&
            gapStrategy != GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS) {
        throw new IllegalArgumentException("invalid gap strategy. Must be GAP_HANDLING_NONE "
                + "or GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS");
    }
    mGapStrategy = gapStrategy;
    setAutoMeasureEnabled(mGapStrategy != GAP_HANDLING_NONE);
    requestLayout();
}
like image 24
Tanay Mondal Avatar answered Nov 18 '22 09:11

Tanay Mondal


Check this on Git

BitFrames

It helps you to set images like you want.

Check this on Play Store

PlayStore App

like image 3
SANAT Avatar answered Nov 18 '22 08:11

SANAT