本文整理了Java中androidx.recyclerview.widget.GridLayoutManager
类的一些代码示例,展示了GridLayoutManager
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridLayoutManager
类的具体详情如下:
包路径:androidx.recyclerview.widget.GridLayoutManager
类名称:GridLayoutManager
暂无
代码示例来源:origin: andkulikov/Transitions-Everywhere
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRecyclerView = new RecyclerView(container.getContext());
mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mRecyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 4));
mRecyclerView.setAdapter(new Adapter());
return mRecyclerView;
}
代码示例来源: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: nickbutcher/plaid
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
// we want the grid to scroll over the top of the toolbar but for the toolbar items
// to be clickable when visible. To achieve this we play games with elevation. The
// toolbar is laid out in front of the grid but when we scroll, we lower it's elevation
// to allow the content to pass in front (and reset when scrolled to top of the grid)
if (newState == RecyclerView.SCROLL_STATE_IDLE
&& layoutManager.findFirstVisibleItemPosition() == 0
&& layoutManager.findViewByPosition(0).getTop() == grid.getPaddingTop()
&& toolbar.getTranslationZ() != 0) {
// at top, reset elevation
toolbar.setTranslationZ(0f);
} else if (newState == RecyclerView.SCROLL_STATE_DRAGGING
&& toolbar.getTranslationZ() != -1f) {
// grid scrolled, lower toolbar to allow content to pass in front
toolbar.setTranslationZ(-1f);
}
}
};
代码示例来源:origin: ybq/Android-SpinKit
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 4);
layoutManager.setOrientation(RecyclerView.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new RecyclerView.Adapter<Holder>() {
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
@SuppressLint("InflateParams") View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, null);
return new Holder(view);
}
@Override
public void onBindViewHolder(Holder holder, int position) {
holder.bind(position);
}
@Override
public int getItemCount() {
return Style.values().length;
}
});
}
代码示例来源:origin: mikepenz/FastAdapter
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
代码示例来源: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: alexvasilkov/GestureViews
@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
super.onDetachedFromRecyclerView(recyclerView);
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
gridManager.setSpanSizeLookup(originalSpanLookup);
originalSpanLookup = null;
spanCount = 1;
}
}
代码示例来源: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: mikepenz/FastAdapter
firstVisiblePosition = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
} else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
firstVisiblePosition = ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
代码示例来源:origin: lisawray/groupie
groupAdapter.setSpanCount(12);
populateAdapter();
layoutManager = new GridLayoutManager(this, groupAdapter.getSpanCount());
layoutManager.setSpanSizeLookup(groupAdapter.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: darkskygit/VirtualApp
private void setGridHeaderFooter(RecyclerView.LayoutManager layoutManager) {
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@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: mikepenz/ItemAnimators
position = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
} else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
position = ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
position = ((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
} else if (mRecyclerView.getLayoutManager() instanceof GridLayoutManager) {
position = ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
代码示例来源:origin: bluelinelabs/Conductor
@Override
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
tvTitle.setText(title);
imgDot.getDrawable().setColorFilter(ContextCompat.getColor(getActivity(), dotColor), Mode.SRC_ATOP);
ViewCompat.setTransitionName(tvTitle, getResources().getString(R.string.transition_tag_title_indexed, fromPosition));
ViewCompat.setTransitionName(imgDot, getResources().getString(R.string.transition_tag_dot_indexed, fromPosition));
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(view.getContext(), 2));
recyclerView.setAdapter(new CityGridAdapter(LayoutInflater.from(view.getContext()), CITY_MODELS));
}
代码示例来源:origin: nickbutcher/plaid
layoutManager = new GridLayoutManager(this, columns);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
代码示例来源: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: 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: turing-tech/MaterialScrollBar
public static boolean initSpanSizeLookup(final RecyclerView rv, final IHeaderAdapter adapter)
{
final RecyclerView.LayoutManager lm = rv.getLayoutManager();
if(lm != null && lm instanceof GridLayoutManager)
{
((GridLayoutManager)lm).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if(rv == null)
return 1;
return adapter.isHeader(position) ? ((GridLayoutManager) lm).getSpanCount() : 1;
}
});
return true;
}
return false;
}
代码示例来源:origin: chrisbanes/PhotoView
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition);
RecyclerView list = findViewById(R.id.list);
list.setLayoutManager(new GridLayoutManager(this, 2));
ImageAdapter imageAdapter = new ImageAdapter(new ImageAdapter.Listener() {
@Override
public void onImageClicked(View view) {
transition(view);
}
});
list.setAdapter(imageAdapter);
}
代码示例来源:origin: contentful/gallery-app-android
private void createLayoutManager() {
layoutManager = new GridLayoutManager(this, GRID_SPAN_COUNT);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override public int getSpanSize(int position) {
return adapter.isSection(position) ? GRID_SPAN_COUNT : 1;
}
});
}
内容来源于网络,如有侵权,请联系作者删除!