当前位置: 首页>>代码示例>>Java>>正文


Java GridLayoutManager.getSpanCount方法代码示例

本文整理汇总了Java中android.support.v7.widget.GridLayoutManager.getSpanCount方法的典型用法代码示例。如果您正苦于以下问题:Java GridLayoutManager.getSpanCount方法的具体用法?Java GridLayoutManager.getSpanCount怎么用?Java GridLayoutManager.getSpanCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.GridLayoutManager的用法示例。


在下文中一共展示了GridLayoutManager.getSpanCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getItemWidth

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
 * 计算每个Item的宽度
 */
public int getItemWidth() {
    final LayoutManager layoutManager = getLayoutManager();
    int itemWidth = 0;
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final int spanCount = gridLayoutManager.getSpanCount();
        if (gridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            itemWidth = getRawWidth() / (mItemCount / spanCount);
        } else {
            itemWidth = getRawWidth() / spanCount;
        }

    } else if (layoutManager instanceof LinearLayoutManager) {
        final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            itemWidth = getRawWidth() / mItemCount;
        } else {
            itemWidth = getRawWidth();
        }
    }

    return itemWidth;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:RecyclerViewPager.java

示例2: 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:FlexibleDividerDecoration.java

示例3: eachPageItemCount

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
 * The number of each page
 *
 * @return
 */
protected int eachPageItemCount() {
    if (mRecyclerView == null) {
        return 0;
    }

    int row = 1;
    RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();

    if (layoutManager != null) {
        if (layoutManager instanceof GridLayoutManager) {
            GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
            row = gridLayoutManager.getSpanCount();
        }
    }

    return row * mPageColumn;
}
 
开发者ID:hanhailong,项目名称:GridPagerSnapHelper,代码行数:23,代码来源:BasePageIndicator.java

示例4: 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;
}
 
开发者ID:dkzwm,项目名称:ItemDecorations,代码行数:30,代码来源:GridItemDecoration.java

示例5: getItemOffsets

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
@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;
}
 
开发者ID:Genius,项目名称:genius-groupie,代码行数:19,代码来源:InsetItemDecoration.java

示例6: getPositionTypeGrid

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private @PositionType int getPositionTypeGrid(RecyclerView parent, int adapterPosition) {
  GridLayoutManager gridLayoutManager = (GridLayoutManager) parent.getLayoutManager();
  int spanSize = gridLayoutManager.getSpanCount();

  int itemPositionType = POSITION_MIDDLE;
  int totalSpanCount = 0;
  boolean isFirstRow = true;

  for (int looper = 0; looper <= adapterPosition; looper++) {
    int currentSpanCount = gridLayoutManager.getSpanSizeLookup().getSpanSize(looper);
    if (totalSpanCount + currentSpanCount > spanSize) {
      totalSpanCount = currentSpanCount;
      isFirstRow = false;
    } else {
      totalSpanCount += currentSpanCount;
    }

    if (looper == adapterPosition) {
      if (totalSpanCount - currentSpanCount == 0) {
        itemPositionType |= POSITION_LEFT;
      }
      if (totalSpanCount == spanSize) {
        itemPositionType |= POSITION_RIGHT;
      }
      if (isFirstRow) {
        itemPositionType |= POSITION_TOP;
      }
      if (isLastRow(gridLayoutManager, adapterPosition, totalSpanCount, spanSize)) {
        itemPositionType |= POSITION_BOTTOM;
      }
    }
  }
  return itemPositionType;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:ItemDecorationManager.java

示例7: bindSearchViews

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void bindSearchViews() {
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this,
            getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? 2 : 3);
    booksAdapter = new BookListAdapter(selectionListener, gridLayoutManager.getSpanCount());

    booksView.setLayoutManager(gridLayoutManager);
    booksView.setAdapter(booksAdapter);

    searchView=(SearchView) findViewById(R.id.search_view);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            View view = SearchActivity.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager)getSystemService(SearchActivity.this.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            clearSearchResults();

            viewModel.search(query);

            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
}
 
开发者ID:approov,项目名称:AppAuth-OAuth2-Books-Demo,代码行数:33,代码来源:SearchActivity.java

示例8: setSpacingForDirection

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
private void setSpacingForDirection(@NonNull final Rect outRect,
                                    @NonNull final RecyclerView.LayoutManager layoutManager,
                                    final int position,
                                    final int itemCount) {
	/* Resolve display mode automatically */
	final int displayMode = resolveDisplayMode(layoutManager);

	switch (displayMode) {
		case HORIZONTAL:
			outRect.left = 0;
			outRect.right = position == itemCount - 1 ? 0 : mHorizontalSpace;
			outRect.top = 0;
			outRect.bottom = 0;
			break;
		case VERTICAL:
			outRect.left = 0;
			outRect.right = 0;
			outRect.top = 0;
			outRect.bottom = position == itemCount - 1 ? 0 : mVerticalSpace;
			break;
		case GRID:
			final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
			final int cols = gridLayoutManager.getSpanCount();
			final int rows = itemCount / cols;

			outRect.left = position % cols == 0 ? 0 : mHorizontalSpace / 2;
			outRect.right = (position + 1) % cols == 0 ? 0 : mHorizontalSpace / 2;
			outRect.top = position < cols ? 0 : mVerticalSpace / 2;
			outRect.bottom = position / cols == rows ? 0 : mVerticalSpace / 2;
			break;
	}
}
 
开发者ID:vivchar,项目名称:RendererRecyclerViewAdapter,代码行数:33,代码来源:BetweenSpacesItemDecoration.java

示例9: setLayoutManager

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
 * 重写此方法,设置GridLayout的上拉加载更多视图的位置
 *
 * @param layout
 */
@Override
public void setLayoutManager(LayoutManager layout) {
    if (layout instanceof GridLayoutManager) {
        final GridLayoutManager externalGridLayoutManager = (GridLayoutManager) layout;
        final int spanCount = externalGridLayoutManager.getSpanCount();
        int orientation = externalGridLayoutManager.getOrientation();

        final GridLayoutManager innerGridLayoutManager = new GridLayoutManager(getContext(), spanCount, orientation, false);
        innerGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int headerViewCount = mInternalAdapter.getHeaderViewCount();
                int footViewCount = mInternalAdapter.getFootViewCount();
                if (position < headerViewCount) {
                    return spanCount;
                }

                int totalItemCount = innerGridLayoutManager.getItemCount();
                if (position >= totalItemCount - footViewCount) {
                    return spanCount;
                }

                return externalGridLayoutManager.getSpanSizeLookup().getSpanSize(position - headerViewCount);
            }
        });
        super.setLayoutManager(innerGridLayoutManager);
    } else {
        super.setLayoutManager(layout);
    }
}
 
开发者ID:Sugarya,项目名称:Closet,代码行数:36,代码来源:EnhanceRecyclerView.java

示例10: checkForNewElements

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public void checkForNewElements(RecyclerView recyclerView) {
	int currentOffset = mLazyFetchingActivity.getCurrentOffset();
	int maxElementsToFetchTotal = mLazyFetchingActivity.getMaxElementsToFetch();

	// If the task has already been run, make a new task as a task can only be run once.
	if(getElementsTask.getStatus() == AsyncTask.Status.FINISHED) {
		getElementsTask = new GetVisualElementsTask<>();
	}

	// Only bother to check if we need to fetch more game objects if we are not already in the process of doing so.
	if(getElementsTask.getStatus() != AsyncTask.Status.RUNNING && currentOffset < maxElementsToFetchTotal) {
		GridLayoutManager lm = (GridLayoutManager) recyclerView.getLayoutManager();
		RecyclerView.Adapter mAdapter = recyclerView.getAdapter();
		if (mAdapter == null ){
			return;
		}

		int lastViewPosition = lm.findLastVisibleItemPosition();
		int spanCount = lm.getSpanCount();
		int itemCount = mAdapter.getItemCount();
		final double FETCH_WHEN_BELOW_FIVE = 5;
		final double NUMBER_OF_ROWS = Math.ceil(itemCount / (spanCount * 1.0)); // Round UP to the nearest Integer
		final double LAST_ROW_VISIBLE = Math.ceil(lastViewPosition/(spanCount * 1.0)); // Round UP to the nearest Integer

		// If the Second to last or the last row is visible, then fetch more game objects.
		if(LAST_ROW_VISIBLE >= NUMBER_OF_ROWS - FETCH_WHEN_BELOW_FIVE) {
			getElementsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mLazyFetchingActivity);
			mLazyFetchingActivity.startProgress();
		}
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:32,代码来源:LazyFetchingOnScrollListener.java

示例11: isLastRaw

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
/**
     * 判断指定位置的Item是否是最后一行
     *
     * @param parent     RecyclerView
     * @param position   位置
     * @param childCount 条目数
     * @return true为最后一行,反之不是
     */
    public static boolean isLastRaw(RecyclerView parent, int position, int childCount, View view) {

        RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
        if (layoutManager instanceof GridLayoutManager) {
            GridLayoutManager manager = (GridLayoutManager) layoutManager;
            int spanCount = manager.getSpanCount();
            int orientation = manager.getOrientation();
            if (orientation == LinearLayoutManager.VERTICAL) {
                int remainder = childCount % spanCount;
                childCount = childCount - remainder - (remainder == 0 ? spanCount : 0);
                // 判断方向竖是否是最后一行
                if (position >= childCount) {
                    return true;
                }
            } else {
                // 判断方向横是否是最后一行
                if ((position + 1) % spanCount == 0) {
                    return true;
                }
            }
        }
//        else if (layoutManager instanceof StaggeredGridLayoutManager) {
//            StaggeredGridLayoutManager manager = (StaggeredGridLayoutManager) layoutManager;
//            int orientation = manager.getOrientation();
//            int spanCount = manager.getSpanCount();
//            if (orientation == StaggeredGridLayoutManager.VERTICAL) {
//                childCount = childCount - childCount % spanCount;
//                // 判断方向竖是否是最后一行
//                if (position >= childCount) {
//                    return true;
//                }
//            } else {
//                // 判断方向横是否是最后一行
//                final StaggeredGridLayoutManager.LayoutParams slp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
//                return slp.getSpanIndex() == spanCount - 1;
//            }
//        }
        return false;
    }
 
开发者ID:crazysunj,项目名称:RecycylerViewItemDecoration,代码行数:48,代码来源:ItemUtil.java

示例12: RecyclerViewEndlessScrollListener

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public RecyclerViewEndlessScrollListener(GridLayoutManager layoutManager) {
    this.mLayoutManager = layoutManager;
    visibleThreshold = visibleThreshold * layoutManager.getSpanCount();
}
 
开发者ID:pawanchauhan05,项目名称:AndroidUtility,代码行数:5,代码来源:RecyclerViewEndlessScrollListener.java

示例13: EndlessRecyclerViewScrollListener

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public EndlessRecyclerViewScrollListener(GridLayoutManager layoutManager) {
    this.mLayoutManager = layoutManager;
    visibleThreshold = visibleThreshold * layoutManager.getSpanCount();
}
 
开发者ID:Implementist,项目名称:iReading,代码行数:5,代码来源:EndlessRecyclerViewScrollListener.java

示例14: EndlessRecyclerViewOnScrollListener

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public EndlessRecyclerViewOnScrollListener(GridLayoutManager layoutManager) {
    mLayoutManager = layoutManager;
    sVisibleThreshold = sVisibleThreshold * layoutManager.getSpanCount();
}
 
开发者ID:prakh25,项目名称:MovieApp,代码行数:5,代码来源:EndlessRecyclerViewOnScrollListener.java

示例15: PhotoGalleryOnScrollListener

import android.support.v7.widget.GridLayoutManager; //导入方法依赖的package包/类
public PhotoGalleryOnScrollListener(GridLayoutManager gridLayoutManager) {
    this.mGridLayoutManager = gridLayoutManager;
    visibleThreshold = visibleThreshold * gridLayoutManager.getSpanCount();
}
 
开发者ID:approov,项目名称:hands-on-api-proxy,代码行数:5,代码来源:PhotoGalleryOnScrollListener.java


注:本文中的android.support.v7.widget.GridLayoutManager.getSpanCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。