androidx.recyclerview.widget.GridLayoutManager.setSpanCount()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中androidx.recyclerview.widget.GridLayoutManager.setSpanCount()方法的一些代码示例,展示了GridLayoutManager.setSpanCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridLayoutManager.setSpanCount()方法的具体详情如下:
包路径:androidx.recyclerview.widget.GridLayoutManager
类名称:GridLayoutManager
方法名:setSpanCount

GridLayoutManager.setSpanCount介绍

暂无

代码示例

代码示例来源:origin: esafirm/android-image-picker

private void setItemDecoration(int columns) {
  if (itemOffsetDecoration != null) {
    recyclerView.removeItemDecoration(itemOffsetDecoration);
  }
  itemOffsetDecoration = new GridSpacingItemDecoration(
      columns,
      context.getResources().getDimensionPixelSize(R.dimen.ef_item_padding),
      false
  );
  recyclerView.addItemDecoration(itemOffsetDecoration);
  layoutManager.setSpanCount(columns);
}

代码示例来源:origin: nguyenhoanglam/ImagePicker

private void setItemDecoration(int columns) {
  if (itemOffsetDecoration != null) {
    recyclerView.removeItemDecoration(itemOffsetDecoration);
  }
  itemOffsetDecoration = new GridSpacingItemDecoration(columns,
      context.getResources().getDimensionPixelSize(R.dimen.imagepicker_item_padding),
      false
  );
  recyclerView.addItemDecoration(itemOffsetDecoration);
  layoutManager.setSpanCount(columns);
}

代码示例来源:origin: gateship-one/odyssey

@Override
  public void onGlobalLayout() {
    final int recyclerViewWidth = mRecyclerView.getWidth();
    if (recyclerViewWidth > 0) {
      // layout finished so remove observer
      mRecyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
      final float gridItemWidth = getResources().getDimensionPixelSize(R.dimen.grid_item_height);
      // the minimum spancount should always be 2
      final int newSpanCount = Math.max((int) Math.floor(recyclerViewWidth / gridItemWidth), 2);
      final GridLayoutManager layoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
      layoutManager.setSpanCount(newSpanCount);
      mRecyclerView.requestLayout();
      // pass the columnWidth to the adapter to adjust the size of the griditems
      final int columnWidth = recyclerViewWidth / newSpanCount;
      ((AlbumsRecyclerViewAdapter) mRecyclerView.getAdapter()).setItemSize(columnWidth);
    }
  }
});

代码示例来源:origin: esafirm/android-image-picker

public void setFolderAdapter(List<Folder> folders) {
  folderAdapter.setData(folders);
  setItemDecoration(folderColumns);
  recyclerView.setAdapter(folderAdapter);
  if (foldersState != null) {
    layoutManager.setSpanCount(folderColumns);
    recyclerView.getLayoutManager().onRestoreInstanceState(foldersState);
  }
}

代码示例来源:origin: nguyenhoanglam/ImagePicker

public void setFolderAdapter(List<Folder> folders) {
  folderAdapter.setData(folders);
  setItemDecoration(folderColumns);
  recyclerView.setAdapter(folderAdapter);
  isShowingFolder = true;
  if (foldersState != null) {
    layoutManager.setSpanCount(folderColumns);
    recyclerView.getLayoutManager().onRestoreInstanceState(foldersState);
  }
}

相关文章