android.support.v7.widget.GridLayoutManager.setSpanCount()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(175)

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

GridLayoutManager.setSpanCount介绍

[英]Sets the number of spans to be laid out.

If #getOrientation() is #VERTICAL, this is the number of columns. If #getOrientation() is #HORIZONTAL, this is the number of rows.
[中]设置要布置的跨距数。
如果#getOrientation()是#垂直的,则这是列数。如果#getOrientation()为#水平,则这是行数。

代码示例

代码示例来源:origin: alibaba/Tangram-Android

@Override
public void cellInited(BaseCell cell) {
  if (cell instanceof LinearScrollCell) {
    this.lSCell = (LinearScrollCell) cell;
    if (lSCell.maxRows > 1) {
      layoutManager.setSpanCount(lSCell.maxRows);
    } else {
      layoutManager.setSpanCount(1);
    }
    totalDistanceOfIndicator = (float) (this.lSCell.defaultIndicatorWidth - this.lSCell.indicatorWidth);
  }
}

代码示例来源:origin: alibaba/Tangram-Android

@Override
public void cellInited(BaseCell cell) {
  if (cell instanceof LinearScrollCell) {
    this.lSCell = (LinearScrollCell) cell;
    if (lSCell.maxRows > 1) {
      layoutManager.setSpanCount(lSCell.maxRows);
    } else {
      layoutManager.setSpanCount(1);
    }
    totalDistanceOfIndicator = (float) (this.lSCell.defaultIndicatorWidth - this.lSCell.indicatorWidth);
  }
}

代码示例来源:origin: hitherejoe/animate

@Override
protected void onMeasure(int widthSpec, int heightSpec) {
  super.onMeasure(widthSpec, heightSpec);
  if (mColumnWidth > 0) {
    int spanCount = Math.max(1, getMeasuredWidth() / mColumnWidth);
    mGridLayoutManager.setSpanCount(spanCount);
  }
}

代码示例来源:origin: naman14/Timber

private void updateLayoutManager(int column) {
  recyclerView.removeItemDecoration(itemDecoration);
  recyclerView.setAdapter(new PlaylistAdapter(getActivity(), PlaylistLoader.getPlaylists(getActivity(), showAuto)));
  layoutManager.setSpanCount(column);
  layoutManager.requestLayout();
  setItemDecoration();
}

代码示例来源:origin: naman14/Timber

private void updateLayoutManager(int column) {
  recyclerView.removeItemDecoration(itemDecoration);
  recyclerView.setAdapter(new AlbumAdapter(getActivity(), AlbumLoader.getAllAlbums(getActivity())));
  layoutManager.setSpanCount(column);
  layoutManager.requestLayout();
  setItemDecoration();
}

代码示例来源:origin: naman14/Timber

private void updateLayoutManager(int column) {
  recyclerView.removeItemDecoration(itemDecoration);
  recyclerView.setAdapter(new ArtistAdapter(getActivity(), ArtistLoader.getAllArtists(getActivity())));
  layoutManager.setSpanCount(column);
  layoutManager.requestLayout();
  setItemDecoration();
}

代码示例来源:origin: ribot/ribot-app-android

@Override
protected void onMeasure(int widthSpec, int heightSpec) {
  super.onMeasure(widthSpec, heightSpec);
  if (mColumnWidth > 0) {
    int spanCount = Math.max(1, getMeasuredWidth() / mColumnWidth);
    mGridLayoutManager.setSpanCount(spanCount);
  }
}

代码示例来源:origin: dongjunkun/GanK

public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback) {
  innerAdapter.onAttachedToRecyclerView(recyclerView);
  RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
  if (layoutManager instanceof GridLayoutManager) {
    final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
    final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
      @Override
      public int getSpanSize(int position) {
        return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
      }
    });
    gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
  }
}

代码示例来源:origin: mcxtzhang/SuspensionIndexBar

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
  mInnerAdapter.onAttachedToRecyclerView(recyclerView);
  //为了兼容GridLayout
  RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
  if (layoutManager instanceof GridLayoutManager) {
    final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
    final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
      @Override
      public int getSpanSize(int position) {
        int viewType = getItemViewType(position);
        if (mHeaderDatas.get(viewType) != null) {
          return gridLayoutManager.getSpanCount();
        } else if (mFooterViews.get(viewType) != null) {
          return gridLayoutManager.getSpanCount();
        }
        if (spanSizeLookup != null)
          return spanSizeLookup.getSpanSize(position);
        return 1;
      }
    });
    gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
  }
}

代码示例来源:origin: Tencent/RapidView

/**
 * Creates a vertical GridLayoutManager
 *
 * @param context Current context, will be used to access resources.
 * @param spanCount The number of columns in the grid
 */
public GridLayoutManager(Context context, int spanCount) {
  super(context);
  setSpanCount(spanCount);
}

代码示例来源:origin: fookwood/Launcher3

/**
 * Sets the number of apps per row.
 */
public void setNumAppsPerRow(int appsPerRow) {
  mAppsPerRow = appsPerRow;
  mGridLayoutMgr.setSpanCount(appsPerRow);
}

代码示例来源:origin: Tencent/RapidView

/**
 * @param context Current context, will be used to access resources.
 * @param spanCount The number of columns or rows in the grid
 * @param orientation Layout orientation. Should be {@link #HORIZONTAL} or {@link
 *                      #VERTICAL}.
 * @param reverseLayout When set to true, layouts from end to start.
 */
public GridLayoutManager(Context context, int spanCount, int orientation,
    boolean reverseLayout) {
  super(context, orientation, reverseLayout);
  setSpanCount(spanCount);
}

代码示例来源:origin: enricocid/LaunchEnr

/**
 * Sets the number of apps per row.
 */
void setNumAppsPerRow(int appsPerRow) {
  mAppsPerRow = appsPerRow;
  mGridLayoutMgr.setSpanCount(appsPerRow);
}

代码示例来源:origin: klinker24/launcher3

/**
 * Sets the number of apps per row.
 */
public void setNumAppsPerRow(int appsPerRow) {
  mAppsPerRow = appsPerRow;
  mGridLayoutMgr.setSpanCount(appsPerRow);
}

代码示例来源:origin: gjiazhe/LayoutSwitch

private void switchLayout() {
  if (gridLayoutManager.getSpanCount() == SPAN_COUNT_ONE) {
    gridLayoutManager.setSpanCount(SPAN_COUNT_THREE);
  } else {
    gridLayoutManager.setSpanCount(SPAN_COUNT_ONE);
  }
  itemAdapter.notifyItemRangeChanged(0, itemAdapter.getItemCount());
}

代码示例来源:origin: xbmc/Kore

@Override
protected void onMeasure(int widthSpec, int heightSpec) {
  super.onMeasure(widthSpec, heightSpec);
  int spanCount = Math.max(1, getMeasuredWidth() / columnWidth);
  multiColumnSupported = spanCount > 1;
  if (columnCount == AUTO_FIT) {
    gridLayoutManager.setSpanCount(spanCount);
  } else {
    gridLayoutManager.setSpanCount(columnCount);
  }
}

代码示例来源:origin: gearvrf/GearVRf-Demos

private void setGridNumColumns(int numColumns) {
  mItemList.clear();
  mRecyclerView.getAdapter().notifyDataSetChanged();
  ((GridLayoutManager) mRecyclerView.getLayoutManager()).setSpanCount(numColumns);
}

代码示例来源:origin: thorbenprimke/realm-recyclerview

@Override
protected void onMeasure(int widthSpec, int heightSpec) {
  super.onMeasure(widthSpec, heightSpec);
  if (gridWidthPx != -1 && gridManager != null && lastMeasuredWidth != getMeasuredWidth()) {
    int spanCount = Math.max(1, getMeasuredWidth() / gridWidthPx);
    gridManager.setSpanCount(spanCount);
    lastMeasuredWidth = getMeasuredWidth();
  }
}

代码示例来源:origin: rohanoid5/Muzesto

private void updateLayoutManager(int column) {
  recyclerView.removeItemDecoration(itemDecoration);
  recyclerView.setAdapter(new AlbumAdapter(getActivity(), AlbumLoader.getAllAlbums(getActivity())));
  layoutManager.setSpanCount(column);
  layoutManager.requestLayout();
  setItemDecoration();
}

代码示例来源:origin: rohanoid5/Muzesto

private void updateLayoutManager(int column) {
  recyclerView.removeItemDecoration(itemDecoration);
  recyclerView.setAdapter(new ArtistAdapter(getActivity(), ArtistLoader.getAllArtists(getActivity())));
  layoutManager.setSpanCount(column);
  layoutManager.requestLayout();
  setItemDecoration();
}

相关文章