当前位置: 首页>>代码示例>>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;未经允许,请勿转载。