本文整理汇总了Java中android.support.v7.widget.GridLayoutManager.setSpanSizeLookup方法的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager.setSpanSizeLookup方法的具体用法?Java GridLayoutManager.setSpanSizeLookup怎么用?Java GridLayoutManager.setSpanSizeLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.GridLayoutManager
的用法示例。
在下文中一共展示了GridLayoutManager.setSpanSizeLookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setBackBtn();
setTitle("ExpandableItem Activity");
setContentView(R.layout.activity_expandable_item_use);
mRecyclerView = (RecyclerView) findViewById(R.id.rv);
list = generateData();
adapter = new ExpandableItemAdapter(list);
final GridLayoutManager manager = new GridLayoutManager(this, 3);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return adapter.getItemViewType(position) == ExpandableItemAdapter.TYPE_PERSON ? 1 : manager.getSpanCount();
}
});
mRecyclerView.setAdapter(adapter);
// important! setLayoutManager should be called after setAdapter
mRecyclerView.setLayoutManager(manager);
adapter.expandAll();
}
示例2: setRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void setRecyclerView() {
layoutManager = new GridLayoutManager(this, 2);
rv_myCustom.setLayoutManager(layoutManager);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
String name = tagBeanList.get(position).getTagName();
if (name.length() > 9) {
return 2;//每个item项占据多少个单元格 每行有两个item 默认是
}
return 1; //每个item项占据多少个单元格
}
});
tagAdapter = new TadAdapter(tagBeanList);
rv_myCustom.setAdapter(tagAdapter);
}
示例3: createNewGridLayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
protected GridLayoutManager createNewGridLayoutManager() {
GridLayoutManager gridLayoutManager = new SmoothScrollGridLayoutManager(getActivity(), mColumnCount);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
// NOTE: If you use simple integers to identify the ViewType,
// here, you should use them and not Layout integers
switch (mAdapter.getItemViewType(position)) {
case R.layout.recycler_scrollable_expandable_item:
case R.layout.recycler_scrollable_header_item:
case R.layout.recycler_scrollable_footer_item:
case R.layout.recycler_scrollable_layout_item:
case R.layout.recycler_scrollable_uls_item:
case R.layout.progress_item:
return mColumnCount;
default:
return 1;
}
}
});
return gridLayoutManager;
}
示例4: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(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);
}
示例5: setUpAdapter
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override protected void setUpAdapter() {
GridLayoutManager glm = new GridLayoutManager(getApplicationContext(), 3);
DragAndDropAdapter adapter = new DragAndDropAdapter(convertDpToPixel(4, this));
adapter.setSpanCount(3);
recyclerView.addItemDecoration(adapter.getItemDecorationManager());
adapter.getItemTouchHelper().attachToRecyclerView(recyclerView);
adapter.setSelectionMode(SelectableAdapter.SELECTION_MODE_MULTIPLE);
glm.setSpanSizeLookup(adapter.getSpanSizeLookup());
recyclerView.setLayoutManager(glm);
recyclerView.setAdapter(adapter);
List<BaseModel> data = new ArrayList<>();
for (int i = 0; i < 50; i++) {
if (i % 10 == 0) {
data.add(new Header("Sample header " + i));
} else {
data.add(GridItem.generateGridItem(i));
}
}
adapter.addData(data);
}
示例6: setGridHeaderFooter
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
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;
}
});
}
}
示例7: 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());
}
}
示例8: initScriptListRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void initScriptListRecyclerView() {
mScriptListView.setAdapter(mScriptListAdapter);
GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
//For directories
if (position > positionOfCategoryDir && position < positionOfCategoryFile()) {
return mDirectorySpanSize;
}
//For files and category
return 2;
}
});
mScriptListView.setLayoutManager(manager);
}
示例9: initRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@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);
}
示例10: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(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 (isFooter(position))
? gridManager.getSpanCount() : 1;
}
});
}
adapter.onAttachedToRecyclerView(recyclerView);
}
示例11: setUpAdapter
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override protected void setUpAdapter() {
GridLayoutManager glm = new GridLayoutManager(getApplicationContext(), 3);
GridAdapter adapter = new GridAdapter(convertDpToPixel(4, this));
adapter.setSpanCount(3);
recyclerView.addItemDecoration(adapter.getItemDecorationManager());
glm.setSpanSizeLookup(adapter.getSpanSizeLookup());
recyclerView.setLayoutManager(glm);
recyclerView.setAdapter(adapter);
List<BaseModel> data = new ArrayList<>();
for (int i = 0; i < 50; i++) {
if (i % 10 == 0) {
data.add(new Header("Sample header " + i));
} else {
data.add(GridItem.generateGridItem(i));
}
}
adapter.addData(data);
}
示例12: adjustSpanSize
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* 解决GridLayoutManager头和脚不占一行的问题
* @param recycler
*/
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;
}
});
}
}
示例13: onCreate
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getContext();
mMediaList = new ArrayList<>();
mNetworkLoader = new NetworkLoader(mContext, this);
boolean isTablet = getResources().getBoolean(R.bool.is_tablet);
boolean isLand = getResources().getBoolean(R.bool.is_land);
mGridCount = ((isTablet && isLand) ? LANDSCAPE_TABLET_GRID_COUNT : (isTablet ? TABLET_GRID_COUNT : DEFAULT_GRID_COUNT));
mLayoutManager = new GridLayoutManager(mContext, mGridCount);
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return (position == mAdapter.getItemCount() - 1) ? mGridCount : 1;
}
});
if (savedInstanceState != null && savedInstanceState.containsKey(PAGE)) {
mPage = savedInstanceState.getInt(PAGE, START_PAGE);
}
//onScrollListener to handle endless pagination
mEndlessScollListener = new EndlessRecyclerViewScrollListener(mPage, mLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
mAdapter.showLoading(true);
mPage = page;
fetchTVShows(page);
}
};
}
示例14: createNewGridLayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
protected GridLayoutManager createNewGridLayoutManager() {
GridLayoutManager gridLayoutManager = new SmoothScrollGridLayoutManager(getActivity(), mColumnCount);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
//noinspection ConstantConditions
return mAdapter.getItem(position).getSpanSize(mColumnCount, position);
}
});
return gridLayoutManager;
}
示例15: onResponse
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onResponse(String response, int id) {
switch (id) {
case 100:
if (response != null) {
processData(response);
adapter = new HomeRecycleAdapter(mContext, resultBean);
rvHome.setAdapter(adapter);
GridLayoutManager manager = new GridLayoutManager(getActivity(), 1);
//设置滑动到哪个位置了的监听
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position <= 3) {
ib_top.setVisibility(View.GONE);
} else {
ib_top.setVisibility(View.VISIBLE);
}
return 1;
}
});
//设置网格布局
rvHome.setLayoutManager(manager);
initListener();
}
break;
case 101:
break;
}
}