當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。