gpt4 book ai didi

android - RecyclerView 自动适配 LayoutManager

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:27:02 31 4
gpt4 key购买 nike

我正在使用 RecyclerViewStaggeredGridLayoutManager

我希望这个 StaggeredGridLayoutManager 或任何一个 LayoutManager 占据空白区域(如果有的话)。例如,如果我设置 spanCount=3即使我有 2 个项目或 1 个项目,它也必须占据所有屏幕宽度。在 StaggeredGridLayoutManager 中,我可以通过以下方式完全跨越单行:setFullSpan(true); 但不能仅在一行中跨越 2 个项目。

我的 RecyclerView 代码:

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

我试过了 AsymmetricGridViewtwoway-view但总有一 block 空地

我收集了一些Facebook App的截图:

enter image description here

这是 Google Keep 应用程序,您可以看到每一行的行高都是固定的,但项目的宽度是灵活的,我从未见过 Google Keep 有任何空白区域:

enter image description here

当我使用它时,总是有一个空白区域,如您所见,图像的黑色部分是空白的。我希望 RecyclerView 应该像在 Google Keep 应用中一样通过扩展我的行来占据该区域:

enter image description here

我访问了这个页面:android-how-to-create-a-facebook-like-images-gallery-grid但这对我没有帮助。

这是我访问的另一个页面:grid-of-images-like-facebook-for-android

有没有人使用 RecyclerView 或任何类似的 View?有人可以建议我任何方式或任何想法或指导我到我必须开始的地方吗?

最佳答案

/**
* 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();
}

关于android - RecyclerView 自动适配 LayoutManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39756256/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com