我正在使用RecyclerView
StaggeredGridLayoutManager
。
我想要StaggeredGridLayoutManager
或LayoutManager
占用空白区域(如果有)。例如,如果我设置spanCount = 3
它必须占据所有屏幕宽度,即使我有2项或1项。在StaggeredGridLayoutManager
我可以完全跨越单行:setFullSpan(true);
但不能跨越两行只有一行。
我的RecyclerView
代码:
StaggeredGridLayoutManager sglm= new StaggeredGridLayoutManager(spanCount,StaggeredGridLayoutManager.VERTICAL);
sglm.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
我尝试了AsymmetricGridView和twoway-view,但总是有一个空白区域
我收集了Facebook App的一些截图:
以下是Google Keep App,因为您可以看到每行的行高都是固定的,但项目的宽度是灵活的,我从未见过Google Keep的任何空白区域:
当我使用它时,总会有一个空白区域,因为你可以看到图像的黑色部分是空的。我希望RecyclerView
应该通过扩展我的行来占用该区域,就像在Google Keep应用中一样:
我访问了此页面:android-how-to-create-a-facebook-like-images-gallery-grid但它没有帮助我。
以下是我访问的另一个页面:grid-of-images-like-facebook-for-android
是否有人使用RecyclerView
或任何View
这样的人?
有人可以建议我任何方式或任何想法或指导我到我必须开始的地方吗?
答案 0 :(得分: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();
}
答案 1 :(得分:3)
答案 2 :(得分:0)
我最近在FlexboxLayoutManager
看到了FlexBox Layout Github。
如果您想获得与Google Keep应用程序相同的效果,则可以使用它。