當前位置: 首頁>>代碼示例>>Java>>正文


Java GridLayoutManager.getOrientation方法代碼示例

本文整理匯總了Java中android.support.v7.widget.GridLayoutManager.getOrientation方法的典型用法代碼示例。如果您正苦於以下問題:Java GridLayoutManager.getOrientation方法的具體用法?Java GridLayoutManager.getOrientation怎麽用?Java GridLayoutManager.getOrientation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.GridLayoutManager的用法示例。


在下文中一共展示了GridLayoutManager.getOrientation方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: setLayoutManager

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
@Override
public void setLayoutManager(LayoutManager layout) {
    super.setLayoutManager(layout);
    canpull = true;
    if (layout instanceof LinearLayoutManager) {
        linearLayoutManager = (LinearLayoutManager) layout;
        if (linearLayoutManager.getOrientation() != VERTICAL)
            canpull = false;
    } else if (layout instanceof GridLayoutManager) {
        gridLayoutManager = (GridLayoutManager) layout;
        if (gridLayoutManager.getOrientation() != VERTICAL)
            canpull = false;
    } else if (layout instanceof StaggeredGridLayoutManager) {
        staggeredGridLayoutManager = (StaggeredGridLayoutManager) layout;
        if (staggeredGridLayoutManager.getOrientation() != VERTICAL)
            canpull = false;
    }
}
 
開發者ID:While1true,項目名稱:JSSample,代碼行數:19,代碼來源:SRecyclerView.java

示例3: getItemHeight

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
public int getItemHeight() {
    final LayoutManager layoutManager = getLayoutManager();
    int itemHeight = 0;
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final int spanCount = gridLayoutManager.getSpanCount();
        if (gridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            itemHeight = getRawHeight() / spanCount;
        } else {
            itemHeight = getRawHeight() / (mItemCount / spanCount);
        }
    } else if (layoutManager instanceof LinearLayoutManager) {
        final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
        if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
            itemHeight = getRawHeight();
        } else {
            itemHeight = getRawHeight() / mItemCount;
        }
    }

    return itemHeight;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:23,代碼來源:RecyclerViewPager.java

示例4: 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

示例5: 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

示例6: offsetsOfGrid

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
/**
 * GridLayoutManager 布局, 計算每個Item, 應該留出的空間(用來繪製分割線的空間)
 */
private void offsetsOfGrid(Rect outRect, GridLayoutManager layoutManager, int viewLayoutPosition) {
    final int spanCount = layoutManager.getSpanCount();
    int itemCount = layoutManager.getItemCount();

    int right = 0, bottom = 0;
    if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
        //垂直方向
        bottom = (int) mDividerSize;
        right = (int) mDividerSize;

        if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判斷是否是最後一排*/) {
            if (drawLastHLine) {
            } else {
                bottom = 0;
            }
        }
        if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判斷是否是最靠右的一排*/) {
            if (drawLastVLine) {
            } else {
                right = 0;
            }
        }
    } else {
        //水平方向
        bottom = (int) mDividerSize;
        right = (int) mDividerSize;

        if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判斷是否是最後一排*/) {
            if (drawLastVLine) {
            } else {
                right = 0;
            }
        }
        if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判斷是否是最靠底部的一排*/) {
            if (drawLastHLine) {
            } else {
                bottom = 0;
            }
        }
    }

    outRect.set(0, 0, right, bottom);
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:47,代碼來源:RBaseItemDecoration.java

示例7: drawGrid

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
protected void drawGrid(Canvas c, RecyclerView.LayoutManager manager) {
    final GridLayoutManager layoutManager = (GridLayoutManager) manager;
    final int spanCount = layoutManager.getSpanCount();
    int itemCount = layoutManager.getItemCount();

    final int firstItem = layoutManager.findFirstVisibleItemPosition();
    for (int i = 0; i < layoutManager.getChildCount(); i++) {
        final View view = layoutManager.findViewByPosition(firstItem + i);
        if (view != null) {
            final RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
            final int viewLayoutPosition = layoutParams.getViewLayoutPosition();//布局時當前View的位置

            if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
                //垂直方向
                if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)/*判斷是否是最後一排*/) {
                    if (viewLayoutPosition == itemCount - 1 /*最後一個*/) {
                        if (drawLastVLine) {
                            drawDrawableV(c, view);
                        }
                        if (drawLastHLine) {
                            drawDrawableH(c, view);
                        }
                    } else {
                        drawDrawableV(c, view);
                    }
                } else {
                    if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)/*判斷是否是最靠右的一排*/) {
                        drawDrawableH(c, view);

                        if (drawLastVLine) {
                            drawDrawableV(c, view);
                        }
                    } else {
                        drawDrawableH(c, view);
                        drawDrawableV(c, view);
                    }
                }
            } else {
                //水平方向
                if (isLastOfGrid(itemCount, viewLayoutPosition, spanCount)) {
                    if (viewLayoutPosition == itemCount - 1 /*最後一個*/) {
                        if (drawLastVLine) {
                            drawDrawableV(c, view);
                        }
                        if (drawLastHLine) {
                            drawDrawableH(c, view);
                        }
                    } else {
                        drawDrawableH(c, view);
                    }
                } else {
                    if (isEndOfGrid(itemCount, viewLayoutPosition, spanCount)) {
                        drawDrawableV(c, view);

                        if (drawLastHLine) {
                            drawDrawableH(c, view);
                        }
                    } else {
                        drawDrawableH(c, view);
                        drawDrawableV(c, view);
                    }
                }
            }
        }
    }
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:67,代碼來源:RBaseItemDecoration.java


注:本文中的android.support.v7.widget.GridLayoutManager.getOrientation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。