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


Java GridLayoutManager.LayoutParams方法代碼示例

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


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

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

示例2: getRecyclerViewDialog

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
public static AlertDialog.Builder getRecyclerViewDialog(Context context, BaseRecyclerAdapter.OnItemClickListener listener) {
    RecyclerView recyclerView = new RecyclerView(context);
    RecyclerView.LayoutParams params =
            new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    recyclerView.setPadding(Util.dipTopx(context, 16), Util.dipTopx(context, 16),
            Util.dipTopx(context, 16), Util.dipTopx(context, 16));
    recyclerView.setLayoutParams(params);
    recyclerView.setLayoutManager(new GridLayoutManager(context, 3));
    CommentItemAdapter adapter = new CommentItemAdapter(context);
    adapter.setOnItemClickListener(listener);
    recyclerView.setAdapter(adapter);
    recyclerView.setOverScrollMode(OVER_SCROLL_NEVER);
    return getDialog(context)
            .setView(recyclerView)
            .setPositiveButton(null, null);
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:17,代碼來源:DialogHelper.java

示例3: isValidHolderAndChild

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
/**
 * Returns whether we consider this a valid view holder for us to draw a divider or section for.
 */
private boolean isValidHolderAndChild(ViewHolder holder, View child,
        List<AlphabeticalAppsList.AdapterItem> items) {
    // Ensure item is not already removed
    GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams)
            child.getLayoutParams();
    if (lp.isItemRemoved()) {
        return false;
    }
    // Ensure we have a valid holder
    if (holder == null) {
        return false;
    }
    // Ensure we have a holder position
    int pos = holder.getPosition();
    if (pos < 0 || pos >= items.size()) {
        return false;
    }
    return true;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:23,代碼來源:AllAppsGridAdapter.java

示例4: getSpanIndex

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
/**
 * get span index of given view in row
 *
 * @param view
 * @return
 */
private int getSpanIndex(View view) {
    if (view.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
        return ((GridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanIndex();
    } else if (view.getLayoutParams() instanceof RecyclerView.LayoutParams) {
        return ((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanIndex();
    }
    return 0;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:15,代碼來源:DividerGridItemDecoration.java

示例5: getSpanSize

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
/**
 * get span size of given view in row
 *
 * @param view
 * @return
 */
private int getSpanSize(View view) {
    if (view.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
        return ((GridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanSize();
    } else if (view.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
        return 1;
    }
    return 0;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:15,代碼來源:DividerGridItemDecoration.java

示例6: getItemOffsets

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

    GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) view.getLayoutParams();
    int position = lp.getSpanIndex();

    if(position == 0){
        outRect.bottom = spacing; // item bottom
        return;
    }

    int column = position % spanCount; // item column

    if (includeEdge) {
        outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
        outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)

        if (position < spanCount) { // top edge
            outRect.top = spacing;
        }
        outRect.bottom = spacing; // item bottom
    } else {
        outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
        outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f /    spanCount) * spacing)
        if (position >= spanCount) {
            outRect.top = spacing; // item top
        }
    }
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:30,代碼來源:GridSpacingItemDecoration.java

示例7: getSpanIndex

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
/**
 * @return the span index of {@link StaggeredGridLayoutManager.LayoutParams} and {@link GridLayoutManager.LayoutParams},
 * otherwise 1 for all other {@link ViewGroup.LayoutParams}
 */
public static <T extends ViewGroup.LayoutParams> int getSpanIndex(@Nullable final T layoutParams) {
    if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
        return ((StaggeredGridLayoutManager.LayoutParams) layoutParams).getSpanIndex();
    } else if (layoutParams instanceof GridLayoutManager.LayoutParams) {
        return ((GridLayoutManager.LayoutParams) layoutParams).getSpanIndex();
    } else {
        return -1;
    }
}
 
開發者ID:Tenor-Inc,項目名稱:tenor-android-core,代碼行數:14,代碼來源:AbstractLayoutManagerUtils.java

示例8: ViewHolder

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
ViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);

    if (mContext.getResources().getInteger(R.integer.categories_column_count) == 1) {
        if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
            GridLayoutManager.LayoutParams params =
                    (GridLayoutManager.LayoutParams) card.getLayoutParams();
            params.leftMargin = 0;
            params.rightMargin = 0;
            params.topMargin = 0;
            params.bottomMargin = 0;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                params.setMarginEnd(0);
            }
        }
    } else {
        setCardViewToFlat(card);
    }

    if (!Preferences.get(mContext).isShadowEnabled()) {
        card.setCardElevation(0f);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        StateListAnimator stateListAnimator = AnimatorInflater
                .loadStateListAnimator(mContext, R.animator.card_lift_long);
        card.setStateListAnimator(stateListAnimator);
    }

    card.setOnClickListener(this);
}
 
開發者ID:danimahardhika,項目名稱:wallpaperboard,代碼行數:34,代碼來源:CategoriesAdapter.java

示例9: getItemOffsets

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, final RecyclerView parent, RecyclerView.State state) {
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
    final int sumCount = state.getItemCount();
    final int position = params.getViewLayoutPosition();
    final int spanSize;
    final int index;

    if (params instanceof GridLayoutManager.LayoutParams) {
        GridLayoutManager.LayoutParams gridParams = (GridLayoutManager.LayoutParams) params;
        spanSize = gridParams.getSpanSize();
        index = gridParams.getSpanIndex();

        if ((position == 0 || mOldItemCount != sumCount) && mSpanCount > 1) {
            int countInLine = 0;
            int spanIndex;

            for (int tempPosition = sumCount - mSpanCount; tempPosition < sumCount; tempPosition++) {
                spanIndex = ((GridLayoutManager) parent.getLayoutManager()).getSpanSizeLookup().getSpanIndex(tempPosition, mSpanCount);
                countInLine = spanIndex == 0 ? 1 : countInLine + 1;
            }
            mItemCountInLastLine = countInLine;
            if (mOldItemCount != sumCount) {
                mOldItemCount = sumCount;
                if (position != 0) {
                    parent.post(new Runnable() {
                        @Override
                        public void run() {
                            parent.invalidateItemDecorations();
                        }
                    });
                }
            }
        }
    } else if (params instanceof StaggeredGridLayoutManager.LayoutParams) {
        spanSize = ((StaggeredGridLayoutManager.LayoutParams) params).isFullSpan() ? mSpanCount : 1;
        index = ((StaggeredGridLayoutManager.LayoutParams) params).getSpanIndex();
    } else {
        spanSize = 1;
        index = 0;
    }

    if (spanSize < 1 || index < 0 || spanSize > mSpanCount) {
        return;
    }

    outRect.left = mSpace - mRadixX * index;
    outRect.right = mRadixX + mRadixX * (index + spanSize - 1);

    if (mSpanCount == 1 && position == sumCount - 1) {
        outRect.bottom = mSpace;
    } else if (position >= sumCount - mItemCountInLastLine && position < sumCount) {
        outRect.bottom = mSpace;
    }
    outRect.top = mSpace;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:57,代碼來源:SpacesItemDecoration.java

示例10: onCreateViewHolder

import android.support.v7.widget.GridLayoutManager; //導入方法依賴的package包/類
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    switch (viewType) {
        case VIEW_TYPE_SECTION_BREAK:
            return new ViewHolder(new View(parent.getContext()));
        case VIEW_TYPE_ICON:
            /* falls through */
        case VIEW_TYPE_PREDICTION_ICON: {
            BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
                    R.layout.all_apps_icon, parent, false);
            icon.setOnClickListener(mIconClickListener);
            icon.setOnLongClickListener(mIconLongClickListener);
            icon.setLongPressTimeout(ViewConfiguration.get(parent.getContext())
                    .getLongPressTimeout());
            icon.setOnFocusChangeListener(mIconFocusListener);

            // Ensure the all apps icon height matches the workspace icons
            DeviceProfile profile = mLauncher.getDeviceProfile();
            Point cellSize = profile.getCellSize();
            GridLayoutManager.LayoutParams lp =
                    (GridLayoutManager.LayoutParams) icon.getLayoutParams();
            lp.height = cellSize.y;
            icon.setLayoutParams(lp);
            return new ViewHolder(icon);
        }
        case VIEW_TYPE_EMPTY_SEARCH:
            return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
                    parent, false));
        case VIEW_TYPE_SEARCH_MARKET:
            View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
                    parent, false);
            searchMarketView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
                }
            });
            return new ViewHolder(searchMarketView);
        case VIEW_TYPE_SEARCH_DIVIDER:
            return new ViewHolder(mLayoutInflater.inflate(
                    R.layout.all_apps_search_divider, parent, false));
        case VIEW_TYPE_PREDICTION_DIVIDER:
            /* falls through */
        case VIEW_TYPE_SEARCH_MARKET_DIVIDER:
            return new ViewHolder(mLayoutInflater.inflate(
                    R.layout.all_apps_divider, parent, false));
        default:
            throw new RuntimeException("Unexpected view type");
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:51,代碼來源:AllAppsGridAdapter.java


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