本文整理汇总了Java中android.support.v7.widget.GridLayoutManager类的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager类的具体用法?Java GridLayoutManager怎么用?Java GridLayoutManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GridLayoutManager类属于android.support.v7.widget包,在下文中一共展示了GridLayoutManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurScrollState
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
/**
* Returns information about the item that the recycler view is currently scrolled to.
*/
protected void getCurScrollState(ScrollPositionState stateOut) {
stateOut.rowIndex = -1;
stateOut.rowTopOffset = -1;
stateOut.rowHeight = -1;
// Return early if there are no items
int rowCount = getAdapter().getItemCount();
if (rowCount == 0) {
return;
}
View child = getChildAt(0);
if (child == null) {
return;
}
stateOut.rowIndex = getChildPosition(child);
if (getLayoutManager() instanceof GridLayoutManager) {
stateOut.rowIndex = stateOut.rowIndex / ((GridLayoutManager) getLayoutManager()).getSpanCount();
}
if(child != null) {
stateOut.rowTopOffset = getLayoutManager().getDecoratedTop(child);
stateOut.rowHeight = child.getHeight();
}
}
示例2: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
@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) {
return (isHeader(position) || isFooter(position) || isRefreshHeader(position))
? gridManager.getSpanCount() : 1;
}
});
}
adapter.onAttachedToRecyclerView(recyclerView);
}
示例3: onCreateView
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Set the adapter
switch (mode) {
case GRID:
binding.list.setLayoutManager(new GridLayoutManager(getActivity(), 4));
break;
case LIST:
binding.list.setLayoutManager(new LinearLayoutManager(getActivity()));
break;
case TILE:
binding.list.setLayoutManager(new GridLayoutManager(getActivity(), 2));
break;
}
return binding.getRoot();
}
示例4: setLayoutManger
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
public SmartRecycleView setLayoutManger(LayoutManagerType layoutManagerType, int orientation, int spanCout) {
RecyclerView.LayoutManager layoutManager = null;
if (layoutManagerType == LayoutManagerType.LINEAR_LAYOUT) {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
linearLayoutManager.setOrientation(orientation);
layoutManager = linearLayoutManager;
} else if (layoutManagerType == LayoutManagerType.GRID_LAYOUT) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, spanCout);
gridLayoutManager.setOrientation(orientation);
layoutManager = gridLayoutManager;
} else if (layoutManagerType == LayoutManagerType.STAGGER_LAYOUT) {
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(spanCout, orientation);
layoutManager = staggeredGridLayoutManager;
}
mRecyclerView.setLayoutManager(layoutManager);
return this;
}
示例5: initActivityCreated
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
@Override
protected void initActivityCreated() {
if (!isPrepared || !isVisible || isLoad) {
return;
}
mAdapter = new XRecyclerViewAdapter<>();
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
recyclerView.setLoadingMore(this);
recyclerView.setAdapter(
mAdapter.setLayoutId(R.layout.item_k567)
.onXBind((holder, position, movieModel) -> {
holder.setTextView(R.id.k567_item_tv, Html.fromHtml(movieModel.title));
ImageLoaderUtils.display(holder.getImageView(R.id.k567_item_iv), movieModel.url);
})
.setOnItemClickListener((view, position, info) -> K567DetailActivity.startIntent(info.title, info.detailUrl, info.url))
);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.post(this::onRefresh);
setLoad();
}
示例6: getLastDividerOffset
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
/**
* In the case mShowLastDivider = false,
* Returns offset for how many views we don't have to draw a divider for,
* for LinearLayoutManager it is as simple as not drawing the last child divider,
* but for a GridLayoutManager it needs to take the span count for the last items into account
* until we use the span count configured for the grid.
*
* @param parent RecyclerView
* @return offset for how many views we don't have to draw a divider or 1 if its a
* LinearLayoutManager
*/
private int getLastDividerOffset(RecyclerView parent) {
if (parent.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
GridLayoutManager.SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
int spanCount = layoutManager.getSpanCount();
int itemCount = parent.getAdapter().getItemCount();
for (int i = itemCount - 1; i >= 0; i--) {
if (spanSizeLookup.getSpanIndex(i, spanCount) == 0) {
return itemCount - i;
}
}
}
return 1;
}
示例7: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
/**
* 当添加到RecyclerView时获取GridLayoutManager布局管理器,修正header和footer显示整行
*
* @param recyclerView the mRecyclerView
*/
@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) {
return getItemViewType(position) == VIEW_TYPE_HEADER || getItemViewType(position) == VIEW_TYPE_FOOTER
? gridManager.getSpanCount() : 1;
}
});
}
}
示例8: isLastColumn
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
private boolean isLastColumn(RecyclerView parent, int pos, int rowCount, int childCount) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % rowCount == 0) { // 如果是最后一列,则不需要绘制右侧分割线
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % rowCount == 0) { // 如果是最后一列,则不需要绘制右侧分割线
return true;
}
} else {
childCount = childCount - childCount % rowCount;
if (pos >= childCount) { // 如果是最后一列,则不需要绘制右侧分割线
return true;
}
}
}
return false;
}
示例9: init
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
public void init() {
new Thread(new Runnable() {
@Override
public void run() {
try {
List<Class> classList = new ClassServiceImpl().getClassListByTeacherId(
new TeacherHelper(getContext()).loadUser().get().getId());
final ClassAdapter classAdapter = new ClassAdapter(getContext(), classList);
final RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 2);
handler.post(new Runnable() {
@Override
public void run() {
recyclerView.setAdapter(classAdapter);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
progressBar.setVisibility(View.INVISIBLE);
}
});
} catch (ClassException e) {
e.printStackTrace();
}
}
}).start();
}
示例10: isLastColum
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
示例11: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
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());
}
}
示例12: initData
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
@Override
protected void initData() {
mItemsBeen = new ArrayList<>();
mTypeItemAdapter = new LiveTypeItemAdapter(mMainActivity, LiveTypeItemAdapter.TYPE_CATE);
mHeaderAndFooterRecyclerViewAdapter = new HeaderAndFooterRecyclerViewAdapter
(mTypeItemAdapter);
mChijiRecyclerView.setAdapter(mHeaderAndFooterRecyclerViewAdapter);
GridLayoutManager manager = new GridLayoutManager(mMainActivity, 2);
manager.setSpanSizeLookup(new HeaderSpanSizeLookup((HeaderAndFooterRecyclerViewAdapter)
mChijiRecyclerView.getAdapter(), manager.getSpanCount()));
mChijiRecyclerView.setLayoutManager(manager);
int spacing = ScreenHelper.dp2px(mMainActivity, 15);
mChijiRecyclerView.addItemDecoration(new SpaceItemDecoration(2, spacing, spacing, false));
mDetailPresenter.attachView(this);
mDetailPresenter.getLiveTypeData(mTypeString, pagerNow, pagerNum);
}
示例13: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
@Override
public void onAttachedToRecyclerView(final 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);
if (mSpanSizeLookup == null) {
return (type == EMPTY_VIEW || type == LOADING_VIEW || type == FETCHING_VIEW) ? gridManager.getSpanCount() : 1;
} else {
return (type == EMPTY_VIEW || type == LOADING_VIEW || type == FETCHING_VIEW) ? gridManager
.getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager, position - getFetchMoreViewCount());
}
}
});
}
}
示例14: isLastColum
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount) {
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
示例15: onCreateView
import android.support.v7.widget.GridLayoutManager; //导入依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View mRootView = inflater.inflate(R.layout.fragment_hotels,container,false);
hotels = new ArrayList<>();
mHotelsList = (RecyclerView) mRootView.findViewById(R.id.hotels_recycler);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
mHotelsList.setLayoutManager(new GridLayoutManager(getActivity(), 2));
}
else {
mHotelsList.setLayoutManager(new GridLayoutManager(getActivity(), 1));
}
mAdapter = new HotelDataAdapter(getActivity(),hotels);
mAdapter.setActionListner(this);
mHotelsList.setAdapter(mAdapter);
if (mPresenter != null)
mPresenter.loadHotels();
return mRootView;
}