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

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

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

GridLayoutManager.getSpanCount介绍

暂无

代码示例

代码示例来源:origin: h6ah4i/android-advancedrecyclerview

public static int getSpanCount(@NonNull RecyclerView rv) {
  RecyclerView.LayoutManager layoutManager = rv.getLayoutManager();
  if (layoutManager instanceof GridLayoutManager) {
    return ((GridLayoutManager) layoutManager).getSpanCount();
  } else if (layoutManager instanceof StaggeredGridLayoutManager) {
    return ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
  } else {
    return 1;
  }
}

代码示例来源:origin: airbnb/epoxy

/**
 * If a grid layout manager is set we sync the span count between the layout and the epoxy
 * adapter automatically.
 */
private void syncSpanCount() {
 LayoutManager layout = getLayoutManager();
 if (layout instanceof GridLayoutManager && epoxyController != null) {
  GridLayoutManager grid = (GridLayoutManager) layout;
  if (epoxyController.getSpanCount() != grid.getSpanCount()
    || grid.getSpanSizeLookup() != epoxyController.getSpanSizeLookup()) {
   epoxyController.setSpanCount(grid.getSpanCount());
   grid.setSpanSizeLookup(epoxyController.getSpanSizeLookup());
  }
 }
}

代码示例来源:origin: lisawray/groupie

@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
  if (!isInset(view, parent)) return;
  GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
  GridLayoutManager gridLayoutManager = (GridLayoutManager) parent.getLayoutManager();
  float spanSize = layoutParams.getSpanSize();
  float totalSpanSize = gridLayoutManager.getSpanCount();
  float n = totalSpanSize / spanSize; // num columns
  float c = layoutParams.getSpanIndex() / spanSize; // column index
  float leftPadding = padding * ((n - c) / n);
  float rightPadding = padding * ((c + 1) / n);
  outRect.left = (int) leftPadding;
  outRect.right = (int) rightPadding;
  outRect.bottom = padding;
}

代码示例来源:origin: alexvasilkov/GestureViews

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
  super.onAttachedToRecyclerView(recyclerView);
  if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
    GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
    spanCount = gridManager.getSpanCount();
    originalSpanLookup = gridManager.getSpanSizeLookup();
    gridManager.setSpanSizeLookup(spanSizes);
  }
}

代码示例来源:origin: airbnb/epoxy

private void calculatePositionDetails(RecyclerView parent, int position, LayoutManager layout) {
 int itemCount = parent.getAdapter().getItemCount();
 firstItem = position == 0;
 lastItem = position == itemCount - 1;
 horizontallyScrolling = layout.canScrollHorizontally();
 verticallyScrolling = layout.canScrollVertically();
 grid = layout instanceof GridLayoutManager;
 if (grid) {
  GridLayoutManager grid = (GridLayoutManager) layout;
  final SpanSizeLookup spanSizeLookup = grid.getSpanSizeLookup();
  int spanSize = spanSizeLookup.getSpanSize(position);
  int spanCount = grid.getSpanCount();
  int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
  isFirstItemInRow = spanIndex == 0;
  fillsLastSpan = spanIndex + spanSize == spanCount;
  isInFirstRow = isInFirstRow(position, spanSizeLookup, spanCount);
  isInLastRow =
    !isInFirstRow && isInLastRow(position, itemCount, spanSizeLookup, spanCount);
 }
}

代码示例来源:origin: crazysunj/MultiTypeRecyclerViewAdapter

@Override
  public int getSpanSize(int position) {
    int itemType = helper.getItemViewType(position);
    if ((itemType >= -1000 && itemType < 0) || (itemType >= -3000 && itemType < -2000)) {
      return layout.getSpanCount();
    }
    return 1;
  }
});

代码示例来源:origin: YassinAJDI/PopularMovies

@Override
  public int getSpanSize(int position) {
    switch (discoverMoviesAdapter.getItemViewType(position)) {
      case R.layout.item_network_state:
        return layoutManager.getSpanCount();
      default:
        return 1;
    }
  }
});

代码示例来源:origin: turing-tech/MaterialScrollBar

public static Integer getSpanSize(RecyclerView rv)
{
  final RecyclerView.LayoutManager lm = rv.getLayoutManager();
  if(lm != null && lm instanceof GridLayoutManager)
    return ((GridLayoutManager)lm).getSpanCount();
  return 1;
}

代码示例来源:origin: turing-tech/MaterialScrollBar

@Override
  public int getSpanSize(int position) {
    if(rv == null)
      return 1;
    return adapter.isHeader(position) ? ((GridLayoutManager) lm).getSpanCount() : 1;
  }
});

代码示例来源:origin: darkskygit/VirtualApp

@Override
  public int getSpanSize(int position) {
    boolean isShowHeader = (position == 0 && hasHeader());
    boolean isShowFooter = (position == getItemCount() - 1 && hasFooter());
    if (isShowFooter || isShowHeader) {
      return gridLayoutManager.getSpanCount();
    }
    return 1;
  }
});

代码示例来源:origin: jruesga/rview

public void setVisibleThreshold(int threshold) {
  visibleThreshold = threshold;
  if (mLayoutManager instanceof GridLayoutManager) {
    visibleThreshold = visibleThreshold *
        ((GridLayoutManager) mLayoutManager).getSpanCount();
  } else if (mLayoutManager instanceof StaggeredGridLayoutManager) {
    visibleThreshold = visibleThreshold *
        ((StaggeredGridLayoutManager) mLayoutManager).getSpanCount();
  }
}

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

@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
  final int position = parent.getChildAdapterPosition(view);
  // get the current number of columns for the grid
  final int spanCount = ((GridLayoutManager) parent.getLayoutManager()).getSpanCount();
  final int left = isFirstInRow(position, spanCount) ? 0 : mHalfSpacingOffsetPX;
  final int top = isInFirstRow(position, spanCount) ? 0 : mSpacingOffsetPX;
  final int right = isLastInRow(position, spanCount) ? 0 : mHalfSpacingOffsetPX;
  // the offset for the bottom should always be 0 because the top margin of the next row will apply.
  outRect.set(left, top, right, 0);
}

代码示例来源:origin: turing-tech/MaterialScrollBar

private int getRowCount() {
  int rowCount = materialScrollBar.recyclerView.getLayoutManager().getItemCount();
  if(materialScrollBar.recyclerView.getLayoutManager() instanceof GridLayoutManager) {
    int spanCount = ((GridLayoutManager) materialScrollBar.recyclerView.getLayoutManager()).getSpanCount();
    rowCount = (int) Math.ceil((double) rowCount / spanCount);
  }
  return rowCount;
}

代码示例来源:origin: pranavpandey/dynamic-support

@Override
  public int getSpanSize(int position) {
    switch (recyclerView.getAdapter().getItemViewType(position)) {
      case DynamicRecyclerViewAdapter.TYPE_EMPTY_VIEW:
      case DynamicRecyclerViewAdapter.TYPE_SECTION_HEADER:
        return ((GridLayoutManager)
            recyclerView.getLayoutManager()).getSpanCount();
      case DynamicRecyclerViewAdapter.TYPE_ITEM:
        return 1;
      default:
        return -1;
    }
  }
});

代码示例来源:origin: turing-tech/MaterialScrollBar

scrollPosState.rowIndex = scrollPosState.rowIndex / ((GridLayoutManager) materialScrollBar.recyclerView.getLayoutManager()).getSpanCount();

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

mScrollSpeed = (int) (1000 / timeScrollPerRow) * ((GridLayoutManager) layoutManager).getSpanCount();
} else {
  mScrollSpeed = (int) (1000 / timeScrollPerRow);

代码示例来源:origin: turing-tech/MaterialScrollBar

void scrollHandleAndIndicator() {
  int scrollBarY;
  getCurScrollState();
  if(customScroller != null) {
    constant = customScroller.getDepthForItem(materialScrollBar.recyclerView.getChildAdapterPosition(materialScrollBar.recyclerView.getChildAt(0)));
  } else {
    constant = scrollPosState.rowHeight * scrollPosState.rowIndex;
  }
  constant += + materialScrollBar.recyclerView.getPaddingTop();
  scrollBarY = (int) getScrollPosition();
  materialScrollBar.handleThumb.setY(scrollBarY);
  materialScrollBar.handleThumb.invalidate();
  if(materialScrollBar.indicator != null) {
    int element;
    if(materialScrollBar.recyclerView.getLayoutManager() instanceof GridLayoutManager) {
      element = scrollPosState.rowIndex * ((GridLayoutManager)materialScrollBar.recyclerView.getLayoutManager()).getSpanCount();
    } else {
      element = scrollPosState.indicatorPosition;
    }
    materialScrollBar.indicator.setText(element);
    materialScrollBar.indicator.setScroll(scrollBarY + materialScrollBar.getTop());
  }
}

代码示例来源:origin: turing-tech/MaterialScrollBar

int spanCount = 1;
if(materialScrollBar.recyclerView.getLayoutManager() instanceof GridLayoutManager) {
  spanCount = ((GridLayoutManager) materialScrollBar.recyclerView.getLayoutManager()).getSpanCount();

相关文章