13

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?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58
  • if black portion is part of image i think it cannot be resolved. however managing screen width and leaving no extra space can be solved. – Developine Oct 07 '16 at 12:27
  • @HammadTariq if you look at Google Keep, its row height fixed for every row and its images is flexible. So you never see the black part on it. I can fix the width but I am always seeing extra space at the bottom of `RecyclerView`. So is there any approach or any way to prevent space at the bottom ? – Yasin Kaçmaz Oct 07 '16 at 13:27
  • You want to assign equal height to all rows ? or each row items should have equal height ? if you want all rows and their items to be equal height then its possible. – Developine Oct 07 '16 at 16:33
  • If you look Google Keep the row height for second row is stable. All items has same height, for third row the same rule. And also if I have 2 items for row and even my span count 3 this two items must occupy all screen width. Also width of items is flexible, not fixed – Yasin Kaçmaz Oct 07 '16 at 16:48

3 Answers3

3
/**
 * 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();
}
Tanay Mondal
  • 147
  • 2
  • 9
3

Check this on Git

BitFrames

It helps you to set images like you want.

Check this on Play Store

PlayStore App

SANAT
  • 8,489
  • 55
  • 66
  • I'll try this project and let you know the result. Thanks – Yasin Kaçmaz Oct 07 '16 at 13:29
  • Are you using this project – Yasin Kaçmaz Oct 07 '16 at 18:20
  • Its my old colleague's project. He is genius. Already implemented in one project. Its awesome. – SANAT Oct 07 '16 at 19:08
  • I tried your way and first of all its not occupies all screen width even I set `android:layout_width="match_parent"` also it limits showing image count to = 4. Here is the screenshot : http://prntscr.com/cr62gn . I want to list images like limitless and it must occupy all screen width. But this library is good comparing to others. – Yasin Kaçmaz Oct 08 '16 at 00:03
  • You can comment there(Git), he will reply you. – SANAT Oct 08 '16 at 05:54
2

I recently saw FlexboxLayoutManager at FlexBox Layout Github.

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

Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58