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

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

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

GridLayoutManager.setSpanSizeLookup介绍

[英]Sets the source to get the number of spans occupied by each item in the adapter.
[中]设置源以获取适配器中每个项占用的跨距数。

代码示例

代码示例来源:origin: janishar/PlaceHolderView

public <T extends GridLayoutManager>PlaceHolderViewBuilder setLayoutManager(T layoutManager, final int spanSizeLookup){
  mLayoutManager = layoutManager;
  ((GridLayoutManager)mLayoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      return spanSizeLookup;
    }
  });
  mRecyclerView.setLayoutManager(mLayoutManager);
  return this;
}

代码示例来源:origin: Aspsine/SwipeToLoadLayout

@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
  RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
  if (layoutManager instanceof GridLayoutManager) {
    final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
      @Override
      public int getSpanSize(int position) {
        RecyclerView.Adapter adapter = recyclerView.getAdapter();
        if (isFullSpanType(adapter.getItemViewType(position))) {
          return gridLayoutManager.getSpanCount();
        }
        return 1;
      }
    });
  }
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
  RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
  if (layoutManager instanceof GridLayoutManager) {
    final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
      @Override
      public int getSpanSize(int position) {
        WrapperAdapter wrapperAdapter = (WrapperAdapter) recyclerView.getAdapter();
        if (isFullSpanType(wrapperAdapter.getItemViewType(position))) {
          return gridLayoutManager.getSpanCount();
        }
        return 1;
      }
    });
  }
}

代码示例来源:origin: dinuscxj/RecyclerRefreshLayout

public void adjustSpanSize(RecyclerView recycler) {
 if(recycler.getLayoutManager() instanceof GridLayoutManager) {
  final GridLayoutManager layoutManager = (GridLayoutManager) recycler.getLayoutManager();
  layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
   @Override
   public int getSpanSize(int position) {
    boolean isHeaderOrFooter =
      isHeaderPosition(position) || isFooterPosition(position);
    return isHeaderOrFooter ? layoutManager.getSpanCount() : 1;
   }
  });
 }
 if(recycler.getLayoutManager() instanceof StaggeredGridLayoutManager) {
  this.mIsStaggeredGrid = true;
 }
}

代码示例来源:origin: Karumi/Rosie

private void initializeComicsView() {
 GridLayoutManager layoutManager = new GridLayoutManager(this, NUMBER_OF_COLUMNS);
 layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
  @Override public int getSpanSize(int position) {
   return position == 0 ? NUMBER_OF_COLUMNS : 1;
  }
 });
 comicsView.setHasFixedSize(true);
 comicsView.setLayoutManager(layoutManager);
 initializeAdapter();
 comicsView.setAdapter(comicDetailsAdapter);
}

代码示例来源:origin: TeamNewPipe/NewPipe

protected RecyclerView.LayoutManager getGridLayoutManager() {
  final Resources resources = activity.getResources();
  int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width);
  width += (24 * resources.getDisplayMetrics().density);
  final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels / (double)width);
  final GridLayoutManager lm = new GridLayoutManager(activity, spanCount);
  lm.setSpanSizeLookup(infoListAdapter.getSpanSizeLookup(spanCount));
  return lm;
}

代码示例来源:origin: TeamNewPipe/NewPipe

protected RecyclerView.LayoutManager getGridLayoutManager() {
  final Resources resources = activity.getResources();
  int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width);
  width += (24 * resources.getDisplayMetrics().density);
  final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels / (double)width);
  final GridLayoutManager lm = new GridLayoutManager(activity, spanCount);
  lm.setSpanSizeLookup(itemListAdapter.getSpanSizeLookup(spanCount));
  return lm;
}

代码示例来源:origin: TeamNewPipe/NewPipe

protected RecyclerView.LayoutManager getGridLayoutManager() {
  final Resources resources = activity.getResources();
  int width = resources.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width);
  width += (24 * resources.getDisplayMetrics().density);
  final int spanCount = (int) Math.floor(resources.getDisplayMetrics().widthPixels / (double)width);
  final GridLayoutManager lm = new GridLayoutManager(activity, spanCount);
  lm.setSpanSizeLookup(infoListAdapter.getSpanSizeLookup(spanCount));
  return lm;
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void initRecyclerView() {
  mSectionedAdapter = new SectionedRecyclerViewAdapter();
  GridLayoutManager mLayoutManager = new GridLayoutManager(BangumiScheduleActivity.this, 3);
  mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      switch (mSectionedAdapter.getSectionItemViewType(position)) {
        case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER:
          return 3;
        default:
          return 1;
      }
    }
  });
  mRecyclerView.setLayoutManager(mLayoutManager);
  mRecyclerView.setAdapter(mSectionedAdapter);
}

代码示例来源:origin: Rukey7/MvpApp

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
  super.onAttachedToRecyclerView(recyclerView);
  RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
  if (manager instanceof GridLayoutManager) {
    final GridLayoutManager gridManager = ((GridLayoutManager) manager);
    gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
      @Override
      public int getSpanSize(int position) {
        int type = getItemViewType(position);
        return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW
            || type == FULL_VIEW || type == FULL_VIEW_2 || type == FULL_VIEW_3) ? gridManager.getSpanCount() : 1;
      }
    });
  }
}

代码示例来源:origin: Rukey7/MvpApp

@Override
  public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
      final GridLayoutManager gridManager = ((GridLayoutManager) manager);
      gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
          int type = getItemViewType(position);
          return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type == LOADING_VIEW) ? gridManager.getSpanCount() : 1;
        }
      });
    }
  }
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void initRecyclerView() {
  mLiveAppIndexAdapter = new LiveAppIndexAdapter(LiveAppIndexActivity.this);
  mRecyclerView.setAdapter(mLiveAppIndexAdapter);
  GridLayoutManager layout = new GridLayoutManager(LiveAppIndexActivity.this, 12);
  layout.setOrientation(LinearLayoutManager.VERTICAL);
  layout.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      return mLiveAppIndexAdapter.getSpanSize(position);
    }
  });
  mRecyclerView.setLayoutManager(layout);
}

代码示例来源:origin: facebook/litho

public GridLayoutInfo(
  Context context,
  int spanCount,
  int orientation,
  boolean reverseLayout,
  boolean allowGridMeasuresOverride) {
 mAllowGridMeasureOverride = allowGridMeasuresOverride;
 mGridLayoutManager =
   mAllowGridMeasureOverride
     ? new GridLayoutManager(context, spanCount, orientation, reverseLayout)
     : new LithoGridLayoutManager(context, spanCount, orientation, reverseLayout);
 mGridSpanSizeLookup = new GridSpanSizeLookup();
 mGridLayoutManager.setSpanSizeLookup(mGridSpanSizeLookup);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
protected void initRecyclerView() {
  mSectionedRecyclerViewAdapter = new SectionedRecyclerViewAdapter();
  GridLayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 1);
  mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      switch (mSectionedRecyclerViewAdapter.getSectionItemViewType(position)) {
        case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER:
          return 1;
        default:
          return 1;
      }
    }
  });
  mRecyclerView.setLayoutManager(mLayoutManager);
  mRecyclerView.setAdapter(mSectionedRecyclerViewAdapter);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void initRecyclerView() {
  mSectionedRecyclerViewAdapter = new SectionedRecyclerViewAdapter();
  GridLayoutManager mLayoutManager = new GridLayoutManager(AdvertisingActivity.this, 2);
  mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      switch (mSectionedRecyclerViewAdapter.getSectionItemViewType(position)) {
        case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER:
          return 2;
        default:
          return 1;
      }
    }
  });
  mRecyclerView.setLayoutManager(mLayoutManager);
  mRecyclerView.setAdapter(mSectionedRecyclerViewAdapter);
  setRecycleNoScroll();
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void initRecyclerView() {
  mSectionedRecyclerViewAdapter = new SectionedRecyclerViewAdapter();
  GridLayoutManager mGridLayoutManager = new GridLayoutManager(SeasonNewBangumiActivity.this, 3);
  mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      switch (mSectionedRecyclerViewAdapter.getSectionItemViewType(position)) {
        case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER:
          return 3;
        default:
          return 1;
      }
    }
  });
  mRecyclerView.setHasFixedSize(true);
  mRecyclerView.setNestedScrollingEnabled(true);
  mRecyclerView.setLayoutManager(mGridLayoutManager);
  mRecyclerView.setAdapter(mSectionedRecyclerViewAdapter);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void initRecyclerView() {
 mRecyclerView.setHasFixedSize(true);
 mGridLayoutManager = new GridLayoutManager(BangumiIndexActivity.this, 3);
 mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
  @Override
  public int getSpanSize(int position) {
   return (0 == position) ? mGridLayoutManager.getSpanCount() : 1;
  }
 });
 mRecyclerView.setLayoutManager(mGridLayoutManager);
 BangumiIndexAdapter mAdapter = new BangumiIndexAdapter(mRecyclerView, categorys);
 mHeaderViewRecyclerAdapter = new HeaderViewRecyclerAdapter(mAdapter);
 createHeadLayout();
 mRecyclerView.setAdapter(mHeaderViewRecyclerAdapter);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
protected void initRecyclerView() {
  mSectionedRecyclerViewAdapter = new SectionedRecyclerViewAdapter();
  GridLayoutManager mLayoutManager = new GridLayoutManager(getActivity(), 2);
  mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      switch (mSectionedRecyclerViewAdapter.getSectionItemViewType(position)) {
        case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER:
          return 2;
        default:
          return 1;
      }
    }
  });
  mRecyclerView.setLayoutManager(mLayoutManager);
  mRecyclerView.setAdapter(mSectionedRecyclerViewAdapter);
  setRecycleNoScroll();
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
protected void initRecyclerView() {
  mLiveAppIndexAdapter = new LiveAppIndexAdapter(getActivity());
  mRecyclerView.setAdapter(mLiveAppIndexAdapter);
  GridLayoutManager layout = new GridLayoutManager(getActivity(), 12);
  layout.setOrientation(LinearLayoutManager.VERTICAL);
  layout.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
      return mLiveAppIndexAdapter.getSpanSize(position);
    }
  });
  mRecyclerView.setLayoutManager(layout);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle state) {
 super.onCreate(state);
 ColumnWeightSpanSizeLookup spanSizer=new ColumnWeightSpanSizeLookup(COLUMN_WEIGHTS);
 GridLayoutManager mgr=new GridLayoutManager(this, spanSizer.getTotalSpans());
 mgr.setSpanSizeLookup(spanSizer);
 setLayoutManager(mgr);
 setAdapter(new VideoAdapter());
 if (state!=null) {
  isInPermission=
   state.getBoolean(STATE_IN_PERMISSION, false);
 }
 if (hasFilesPermission()) {
  loadVideos();
 }
 else if (!isInPermission) {
  isInPermission=true;
  ActivityCompat.requestPermissions(this,
   new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
   REQUEST_PERMS);
 }
}

相关文章