本文整理汇总了Java中android.support.v7.widget.GridLayoutManager.SpanSizeLookup方法的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager.SpanSizeLookup方法的具体用法?Java GridLayoutManager.SpanSizeLookup怎么用?Java GridLayoutManager.SpanSizeLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.GridLayoutManager
的用法示例。
在下文中一共展示了GridLayoutManager.SpanSizeLookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public static void onAttachedToRecyclerView(RecyclerView recyclerView, final RecyclerView.Adapter adapter, final int pinnedHeaderType) {
// 如果是网格布局,这里处理标签的布局占满一行
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
final GridLayoutManager.SpanSizeLookup oldSizeLookup = gridLayoutManager.getSpanSizeLookup();
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (adapter.getItemViewType(position) == pinnedHeaderType) {
return gridLayoutManager.getSpanCount();
}
if (oldSizeLookup != null) {
return oldSizeLookup.getSpanSize(position);
}
return 1;
}
});
}
}
示例2: 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());
}
}
示例3: 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());
}
}
示例4: isTop
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* is position align top of recycler view
* 从当前位置找起,只要找到一个跟自己的spanIndex一样的就说明不是第一行,或者已经查找过的spancount >= spanCount说明不是第一行
*
* @param parent
* @param position
* @param totalSpanCount
* @return
*/
private boolean isTop(RecyclerView parent, int position, int totalSpanCount) {
if (parent.getLayoutManager() instanceof GridLayoutManager) {
GridLayoutManager.SpanSizeLookup sizeLookup = ((GridLayoutManager) parent.getLayoutManager()).getSpanSizeLookup();
if (sizeLookup != null) {
int currentSpanIndex = sizeLookup.getSpanIndex(position, totalSpanCount);
int lookupedSpanCount = 0;
for (int i = position - 1; i >= 0; i--) {
lookupedSpanCount = lookupedSpanCount + sizeLookup.getSpanSize(i);
if (lookupedSpanCount >= totalSpanCount) {
return false;
}
if (sizeLookup.getSpanIndex(i, totalSpanCount) == currentSpanIndex) {
return false;
}
}
return true;
}
} else if (parent.getLayoutManager() instanceof StaggeredGridLayoutManager) {
return position < totalSpanCount;//staggered 的每一列一个span
}
return false;
}
示例5: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
mInnerAdapter.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) {
int viewType = getItemViewType(position);
if (mHeaderViews.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());
}
}
示例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: getTotalSpanSizeByPosition
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* Gets the total number of spans by the position
*
* @param manager The GridLayoutManager
* @param position The position of Item
* @return
*/
private int getTotalSpanSizeByPosition(GridLayoutManager manager, int position) {
int spanTotalSize = 0;
GridLayoutManager.SpanSizeLookup lookup = manager.getSpanSizeLookup();
int spanCount = manager.getSpanCount();
for (int i = 0; i <= position; i++) {
int spanLookup = lookup.getSpanSize(i);
spanTotalSize = spanTotalSize + spanLookup;
if (spanTotalSize >= spanCount) {
if (spanTotalSize % spanCount != 0) {
spanTotalSize = spanLookup;
} else {
if (spanTotalSize > spanCount) {
if (spanTotalSize % spanCount != 0)
spanTotalSize = spanTotalSize % spanCount;
else
spanTotalSize = spanCount;
}
}
}
}
return spanTotalSize;
}
示例8: recoverLayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void recoverLayoutManager(LayoutManager layoutManager) {
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
if (spanSizeLookup instanceof FixedViewSpanSizeLookup) {
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.DefaultSpanSizeLookup());
((FixedViewSpanSizeLookup) spanSizeLookup).detach();
}
}
}
开发者ID:TakWolf,项目名称:Android-HeaderAndFooterRecyclerView,代码行数:11,代码来源:HeaderAndFooterRecyclerView.java
示例9: setlayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void setlayoutManager(RecyclerView recyclerView) {
final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
Object item = items.get(position);
if (item instanceof Bean01) {
return 1;
}
if (item instanceof Bean02) {
return 2;
}
if (item instanceof Bean03) {
return SPAN_COUNT;
}
if (item instanceof Bean04) {
return SPAN_COUNT;
}
if (item instanceof String) {
return SPAN_COUNT;
}
return SPAN_COUNT;
}
};
layoutManager.setSpanSizeLookup(spanSizeLookup);
recyclerView.setLayoutManager(layoutManager);
// recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
示例10: setLayoutManager
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void setLayoutManager(RecyclerView recyclerView) {
final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(SPAN_COUNT, StaggeredGridLayoutManager.VERTICAL);
GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
Object item = items.get(position);
if (item instanceof Bean01) {
return 1;
}
if (item instanceof Bean02) {
return 1;
}
if (item instanceof Bean03) {
return SPAN_COUNT;
}
if (item instanceof Bean04) {
return SPAN_COUNT;
}
if (item instanceof String) {
return SPAN_COUNT;
}
return 1;
}
};
// layoutManager.setSpanSizeLookup(spanSizeLookup);
// layoutManager.setSpanCount(2);
recyclerView.setLayoutManager(layoutManager);
}
示例11: unbind
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
* This method unsubscribe observer and change listeners reference to null
* for avoid memory leaks.
*/
public void unbind() {
if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
wrapperAdapter.unbind();
userAdapter.unregisterAdapterDataObserver(wrapperAdapterObserver);
recyclerView.setAdapter(userAdapter);
} else if (recyclerView.getLayoutManager() instanceof GridLayoutManager && wrapperSpanSizeLookup != null) {
GridLayoutManager.SpanSizeLookup spanSizeLookup = wrapperSpanSizeLookup.getWrappedSpanSizeLookup();
((GridLayoutManager) recyclerView.getLayoutManager()).setSpanSizeLookup(spanSizeLookup);
}
}
示例12: getSpanSizeLookup
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public GridLayoutManager.SpanSizeLookup getSpanSizeLookup() {
return spanSizeLookup;
}
示例13: onCreate
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multidata);
adapter = new MultiTypeAdapter();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rlv_multidata);
adapter.register(Bean04.class, new ItemVIew06());
adapter.register(String.class, new ItemVIewNormal());
final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
Object item = items.get(position);
if (item instanceof Bean04) {
return SPAN_COUNT;
}
if (item instanceof String) {
return SPAN_COUNT;
}
return 1;
}
};
layoutManager.setSpanSizeLookup(spanSizeLookup);
recyclerView.setLayoutManager(layoutManager);
int space = getResources().getDimensionPixelSize(R.dimen.normal_space);
recyclerView.addItemDecoration(new ItemDecoration(space));
recyclerView.setAdapter(adapter);
items = new ArrayList<>();
for(int j=0;j<10;j++) {
items.add(" 单数据 -> 多类型 ");
for (int i = 0; i < 6; i++) {
Bean04 bean04 = new Bean04("bean04_" + i);
if (i % 1 == 0) {
bean04.setType(Bean04.TYPE_ONE);
}
if (i % 2 == 0) {
bean04.setType(Bean04.TYPE_TWO);
}
if (i % 3 == 0) {
bean04.setType(Bean04.TYPE_THREE);
}
items.add(bean04);
}
}
adapter.setItems(items);
adapter.notifyDataSetChanged();
}
示例14: onCreate
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multidata);
adapter = new MultiTypeAdapter();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rlv_multidata);
adapter.register(String.class, new ItemVIewNormal());
adapter.register(Bean01.class, new ItemVIew01());
adapter.register(Bean02.class, new ItemVIew02());
adapter.register(Bean03.class, new ItemVIew03());
adapter.register(Bean04.class, new ItemVIew06());
final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
Object item = items.get(position);
if (item instanceof Bean01) {
return 1;
}
if (item instanceof Bean02) {
return 2;
}
if (item instanceof Bean03) {
return SPAN_COUNT;
}
if (item instanceof Bean04 ) {
return SPAN_COUNT;
}
if (item instanceof String) {
return SPAN_COUNT;
}
return 2;
}
};
layoutManager.setSpanSizeLookup(spanSizeLookup);
recyclerView.setLayoutManager(layoutManager);
int space = getResources().getDimensionPixelSize(R.dimen.normal_space);
recyclerView.addItemDecoration(new ItemDecoration(space));
recyclerView.setAdapter(adapter);
items = new ArrayList<>();
for(int j=0;j<10;j++) {
items.add("混合式 \n 多数据 -> 多类型 单数据 -> 多类型");
for (int i = 0; i < 3; i++) {
Bean04 bean04 = new Bean04("bean04_" + i);
if (i % 1 == 0) {
bean04.setType(Bean04.TYPE_ONE);
}
if (i % 2 == 0) {
bean04.setType(Bean04.TYPE_TWO);
}
if (i % 3 == 0) {
bean04.setType(Bean04.TYPE_THREE);
}
items.add(bean04);
}
for (int i = 0; i < 8; i++) {
items.add(new Bean01("bean01_" + i));
}
for (int i = 0; i < 3; i++) {
items.add(new Bean02("bean02_" + i));
}
for (int i = 0; i < 1; i++) {
items.add(new Bean03("bean03_" + i));
}
}
// layoutManager.setSpanSizeLookup(spanSizeLookup);
adapter.setItems(items);
adapter.notifyDataSetChanged();
}
示例15: onAttachedToRecyclerView
import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView)
{
mInnerAdapter.onAttachedToRecyclerView(recyclerView);
final 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)
{
if (isShowLoadView(position))
{
return gridLayoutManager.getSpanCount();
}
if (spanSizeLookup != null)
{
return spanSizeLookup.getSpanSize(position);
}
return 1;
}
});
gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
}
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
lastY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
isPullUp = event.getRawY() < lastY ;
break;
}
lastY = event.getRawY();
return false;
}
});
recyclerView.addOnScrollListener(new OnRcvScrollListener(){
@Override
protected void onLoadMore() {
super.onLoadMore();
if(isEnableLoad() && isPullUp && !mRefreshing){
isLoadingMore = true;
mOnLoadMoreListener.onLoad();
}
}
@Override
protected void showLoadView() {
super.showLoadView();
if(isEnableLoad() && isPullUp && !mRefreshing) {
mLoadView.setLoadViewType(BaseLoadView.TYPE_LOAD_MORE);
}
}
});
}