Java Code Examples for android.support.v7.widget.StaggeredGridLayoutManager#LayoutParams
The following examples show how to use
android.support.v7.widget.StaggeredGridLayoutManager#LayoutParams .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderRecyclerAndFooterWrapperAdapter.java From all-base-adapter with Apache License 2.0 | 6 votes |
@Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { mInnerAdapter.onViewAttachedToWindow(holder); int position = holder.getLayoutPosition(); if (isHeaderViewPos(position) || isFooterViewPos(position)) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } } }
Example 2
Source File: StaggeredSpaceDecoration.java From ItemDecorationDemo with Apache License 2.0 | 6 votes |
/** * orientation为Vertical时调用,处理Vertical下的Offset * {@link #getItemOffsets(Rect, View, RecyclerView, RecyclerView.State)} */ private void handleVertical(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent) { StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams(); int spanIndex = params.getSpanIndex(); int adapterPos = parent.getChildAdapterPosition(view); int sizeAvg = (int) ((mHorizontal * (mSpanCount - 1) + mLeft + mRight) * 1f / mSpanCount); int left = computeLeft(spanIndex, sizeAvg); int right = computeRight(spanIndex, sizeAvg); outRect.left = left; outRect.right = right; outRect.top = mVertical / 2; outRect.bottom = mVertical / 2; if (isFirstRaw(adapterPos, spanIndex)) { //第一行 outRect.top = mTop; } if (isLastRaw(spanIndex)) { //最后一行 outRect.bottom = mBottom; } }
Example 3
Source File: RecyclerAdapterWithHF.java From CommonPullToRefresh with Apache License 2.0 | 6 votes |
private void prepareHeaderFooter(HeaderFooterViewHolder vh, View view) { // if it's a staggered grid, span the whole layout if (mManagerType == TYPE_MANAGER_STAGGERED_GRID) { StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.setFullSpan(true); vh.itemView.setLayoutParams(layoutParams); } // if the view already belongs to another layout, remove it if (view.getParent() != null) { ((ViewGroup) view.getParent()).removeView(view); } // empty out our FrameLayout and replace with our header/footer vh.base.removeAllViews(); vh.base.addView(view); }
Example 4
Source File: HeaderAndFooterWrapper.java From styT with Apache License 2.0 | 6 votes |
@Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { super.onViewAttachedToWindow(holder); int position = holder.getLayoutPosition(); if (isHeaderViewPos(position) || isFooterViewPos(position)) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } } }
Example 5
Source File: BaseAdapter.java From MvpRoute with Apache License 2.0 | 6 votes |
/** * 解决StaggeredGridLayoutManager问题 * * @param holder */ @Override public void onViewAttachedToWindow(V holder) { super.onViewAttachedToWindow(holder); int position = holder.getLayoutPosition(); if (isHeaderPos(position) || isFooterPos(position)) { ViewGroup.LayoutParams lp = holder.getItemView().getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } } }
Example 6
Source File: LoadMoreCommonAdapter.java From likequanmintv with Apache License 2.0 | 5 votes |
private void setFullSpan(RecyclerView.ViewHolder holder) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } }
Example 7
Source File: HomeAdapter.java From candybar-library with Apache License 2.0 | 5 votes |
IconRequestViewHolder(View itemView) { super(itemView); title = itemView.findViewById(R.id.title); installedApps = itemView.findViewById(R.id.installed_apps); missedApps = itemView.findViewById(R.id.missed_apps); themedApps = itemView.findViewById(R.id.themed_apps); progress = itemView.findViewById(R.id.progress); container = itemView.findViewById(R.id.container); CardView card = itemView.findViewById(R.id.card); if (CandyBarApplication.getConfiguration().getHomeGrid() == CandyBarApplication.GridStyle.FLAT) { if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) { card.setRadius(0f); card.setUseCompatPadding(false); int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin); StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams(); params.setMargins(0, 0, margin, margin); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { params.setMarginEnd(margin); } } } if (!Preferences.get(mContext).isCardShadowEnabled()) { card.setCardElevation(0); } int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary); title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable( mContext, R.drawable.ic_toolbar_icon_request, color), null, null, null); int accent = ColorHelper.getAttributeColor(mContext, R.attr.colorAccent); progress.getProgressDrawable().setColorFilter(accent, PorterDuff.Mode.SRC_IN); container.setOnClickListener(this); }
Example 8
Source File: FlexAdapter.java From customview-samples with Apache License 2.0 | 5 votes |
@NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { View view = LayoutInflater.from(viewGroup.getContext()) .inflate(getLayoutId(viewType), viewGroup, false); if(viewType != ITEM_TYPE_4) { Pair<Integer, Integer> pair = getWHRatioByType(viewGroup.getWidth(), ITEM_HEIGHT, viewType); view.setLayoutParams(new ViewGroup.LayoutParams(pair.first, pair.second)); }else{ StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,SizeUtils.dp2px(50)); layoutParams.setFullSpan(true); view.setLayoutParams(layoutParams); } return new FlexViewHolder(view); }
Example 9
Source File: BaseHeadRecyclerAdapter.java From MeiZiNews with MIT License | 5 votes |
@Override public void onViewAttachedToWindow(BaseAdapterHelper holder) { super.onViewAttachedToWindow(holder); ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams && holder.getLayoutPosition() == 0) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } }
Example 10
Source File: WrapperUtils.java From Bailan with Apache License 2.0 | 5 votes |
public static void setFullSpan(RecyclerView.ViewHolder holder) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } }
Example 11
Source File: SwipeAdapterWrapper.java From SwipeRecyclerView-master with Apache License 2.0 | 5 votes |
@Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { int position = holder.getAdapterPosition(); if (isHeaderView(position) || isFooterView(position)) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } } else { mAdapter.onViewAttachedToWindow(holder); } }
Example 12
Source File: PowerfulRecyclerAdapter.java From PowerfulRecyclerView with Apache License 2.0 | 5 votes |
@Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { super.onViewAttachedToWindow(holder); ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams && ((holder.getLayoutPosition() == this.getItemCount() - 1 && hasFootView()) || (holder.getLayoutPosition() < getHeaderViewCount()) && hasHeaderView())) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } }
Example 13
Source File: StageredLoadMoreAdapter.java From YCRefreshView with Apache License 2.0 | 5 votes |
@Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { super.onViewAttachedToWindow(holder); ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams(); if (layoutParams != null && layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) layoutParams; int position = holder.getLayoutPosition(); //如果是上拉加载更多类型,则设置setFullSpan为true,那么它就会占一行 if (getItemViewType(position) == footType) { params.setFullSpan(true); } } }
Example 14
Source File: HuaBanAdapter.java From v9porn with MIT License | 5 votes |
@Override protected void convert(BaseViewHolder helper, HuaBan.Picture item) { ImageView imageView = helper.getView(R.id.iv_item_hua_ban); GlideApp.with(helper.itemView.getContext()).load(item.getPictureUrl(item.getPictureKey(), width)).transition(new DrawableTransitionOptions().crossFade(300)).into(imageView); int height; if (!heightMap.containsKey(item.getPictureKey())) { height = item.getPictureHeight() * width / item.getPictureWidth(); heightMap.put(item.getPictureKey(), height); } else { height = heightMap.get(item.getPictureKey()); } StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) helper.itemView.getLayoutParams(); layoutParams.height = height; helper.itemView.setLayoutParams(layoutParams); }
Example 15
Source File: DParent.java From kernel_adiutor with Apache License 2.0 | 5 votes |
private void setUpLayout() { if (fullspan && view != null) { StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setFullSpan(true); int padding = view.getContext().getResources().getDimensionPixelSize(R.dimen.basecard_padding); layoutParams.setMargins(padding, padding, padding, 0); view.setLayoutParams(layoutParams); } }
Example 16
Source File: MeiZiTuAdapter.java From v9porn with MIT License | 5 votes |
@Override protected void convert(BaseViewHolder helper, MeiZiTu item) { ImageView imageView = helper.getView(R.id.iv_item_mei_zi_tu); GlideApp.with(helper.itemView.getContext()).load(buildGlideUrl(item.getThumbUrl())).transition(new DrawableTransitionOptions().crossFade(300)).into(imageView); int height; if (!heightMap.containsKey(item.getThumbUrl())) { height = item.getHeight() * width / item.getWidth(); heightMap.put(item.getThumbUrl(), height); } else { height = heightMap.get(item.getThumbUrl()); } StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) helper.itemView.getLayoutParams(); layoutParams.height = height; helper.itemView.setLayoutParams(layoutParams); }
Example 17
Source File: ShieldDisplayNodeAdapter.java From Shield with MIT License | 5 votes |
private void onBindViewHolder(@NonNull DNViewHolder holder, int position, @NonNull ShieldDisplayNode displayNode) { isOnBind = true; if (holder.itemView instanceof DisplayNodeContainer) { ShieldDisplayNode oldNode = ((DisplayNodeContainer) holder.itemView).getNode(); if (oldNode != null) { oldNode.containerView = null; } ((DisplayNodeContainer) holder.itemView).setNode(displayNode); displayNode.containerView = (DisplayNodeContainer) holder.itemView; displayNode.view = ((DisplayNodeContainer) holder.itemView).getSubView(); } else { displayNode.containerView = null; displayNode.view = holder.itemView; } holder.displayNode = displayNode; if (displayNode.viewPaintingCallback != null) { displayNode.viewPaintingCallback.updateView(displayNode.view, displayNode, displayNode.getPath()); } //add StaggeredGrid support StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) displayNode.containerView.getLayoutParams(); if (displayNode.rowParent != null && displayNode.rowParent.sectionParent instanceof StaggeredGridSection && displayNode.getPath() != null && (displayNode.getPath().cellType == CellType.NORMAL || displayNode.getPath().cellType == CellType.LOADING_MORE)) { layoutParams.setFullSpan(false); } else { layoutParams.setFullSpan(true); } displayNode.containerView.setLayoutParams(layoutParams); isOnBind = false; }
Example 18
Source File: HeaderAndFooterAdapterWrapper.java From NoListAdapter with Apache License 2.0 | 5 votes |
@Override public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) { mAdapter.onViewAttachedToWindow(holder); int position = holder.getLayoutPosition(); if (isHeaderViewPos(position) || isFooterViewPos(position)) { ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams(); if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) { StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp; p.setFullSpan(true); } } }
Example 19
Source File: AboutAdapter.java From candybar-library with Apache License 2.0 | 4 votes |
FooterViewHolder(View itemView) { super(itemView); ImageView instagram = itemView.findViewById(R.id.about_dev_instagram); ImageView googlePlus = itemView.findViewById(R.id.about_dev_google_plus); ImageView github = itemView.findViewById(R.id.about_dev_github); TextView title = itemView.findViewById(R.id.about_dashboard_title); TextView licenses = itemView.findViewById(R.id.about_dashboard_licenses); TextView contributors = itemView.findViewById(R.id.about_dashboard_contributors); TextView translator = itemView.findViewById(R.id.about_dashboard_translator); CardView card = itemView.findViewById(R.id.card); if (CandyBarApplication.getConfiguration().getAboutStyle() == CandyBarApplication.Style.PORTRAIT_FLAT_LANDSCAPE_FLAT && card != null) { if (card.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) { card.setRadius(0f); card.setUseCompatPadding(false); int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin); StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) card.getLayoutParams(); params.setMargins(0, 0, margin, margin); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { params.setMarginEnd(margin); } } } if (!Preferences.get(mContext).isCardShadowEnabled()) { if (card != null) card.setCardElevation(0); } int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary); title.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable( mContext, R.drawable.ic_toolbar_dashboard, color), null, null, null); color = ConfigurationHelper.getSocialIconColor(mContext, CandyBarApplication.getConfiguration().getSocialIconColor()); instagram.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_instagram, color)); googlePlus.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_google_plus, color)); github.setImageDrawable(DrawableHelper.getTintedDrawable(mContext, R.drawable.ic_toolbar_github, color)); instagram.setOnClickListener(this); googlePlus.setOnClickListener(this); github.setOnClickListener(this); licenses.setOnClickListener(this); contributors.setOnClickListener(this); translator.setOnClickListener(this); }
Example 20
Source File: HomeAdapter.java From candybar-library with Apache License 2.0 | 4 votes |
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { try { if (holder.itemView != null) { StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams(); layoutParams.setFullSpan(isFullSpan(holder.getItemViewType())); } } catch (Exception e) { LogUtil.d(Log.getStackTraceString(e)); } if (holder.getItemViewType() == TYPE_HEADER) { HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder; headerViewHolder.title.setText(mContext.getResources().getString(R.string.home_title)); headerViewHolder.content.setHtml(mContext.getResources().getString(R.string.home_description)); String uri = mContext.getResources().getString(R.string.home_image); if (URLUtil.isValidUrl(uri)) { ImageLoader.getInstance().displayImage(uri, headerViewHolder.image, ImageConfig.getDefaultImageOptions(true)); } else if (ColorHelper.isValidColor(uri)) { headerViewHolder.image.setBackgroundColor(Color.parseColor(uri)); } else { uri = "drawable://" + DrawableHelper.getResourceId(mContext, uri); ImageLoader.getInstance().displayImage(uri, headerViewHolder.image, ImageConfig.getDefaultImageOptions(true)); } } else if (holder.getItemViewType() == TYPE_CONTENT) { ContentViewHolder contentViewHolder = (ContentViewHolder) holder; int finalPosition = position - 1; int color = ColorHelper.getAttributeColor(mContext, android.R.attr.textColorPrimary); if (mHomes.get(finalPosition).getIcon() != -1) { if (mHomes.get(finalPosition).getType() == Home.Type.DIMENSION) { contentViewHolder.autoFitTitle.setCompoundDrawablesWithIntrinsicBounds( DrawableHelper.getResizedDrawable(mContext, DrawableHelper.get(mContext, mHomes.get(finalPosition).getIcon()), 40), null, null, null); } else { contentViewHolder.autoFitTitle.setCompoundDrawablesWithIntrinsicBounds(DrawableHelper.getTintedDrawable( mContext, mHomes.get(finalPosition).getIcon(), color), null, null, null); } } if (mHomes.get(finalPosition).getType() == Home.Type.ICONS) { contentViewHolder.autoFitTitle.setSingleLine(true); contentViewHolder.autoFitTitle.setMaxLines(1); contentViewHolder.autoFitTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContext.getResources().getDimension(R.dimen.text_max_size)); contentViewHolder.autoFitTitle.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); contentViewHolder.autoFitTitle.setIncludeFontPadding(false); contentViewHolder.autoFitTitle.setSizeToFit(true); contentViewHolder.subtitle.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); } else { contentViewHolder.autoFitTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, mContext.getResources() .getDimension(R.dimen.text_content_title)); } contentViewHolder.autoFitTitle.setText(mHomes.get(finalPosition).getTitle()); if (mHomes.get(finalPosition).getSubtitle().length() > 0) { contentViewHolder.subtitle.setText(mHomes.get(finalPosition).getSubtitle()); contentViewHolder.subtitle.setVisibility(View.VISIBLE); } } else if (holder.getItemViewType() == TYPE_ICON_REQUEST) { IconRequestViewHolder iconRequestViewHolder = (IconRequestViewHolder) holder; int installed = CandyBarMainActivity.sInstalledAppsCount; int missed = CandyBarMainActivity.sMissedApps == null ? installed : CandyBarMainActivity.sMissedApps.size(); int themed = installed - missed; iconRequestViewHolder.installedApps.setText(String.format( mContext.getResources().getString(R.string.home_icon_request_installed_apps), installed)); iconRequestViewHolder.missedApps.setText(String.format( mContext.getResources().getString(R.string.home_icon_request_missed_apps), missed)); iconRequestViewHolder.themedApps.setText(String.format( mContext.getResources().getString(R.string.home_icon_request_themed_apps), themed)); iconRequestViewHolder.progress.setMax(installed); iconRequestViewHolder.progress.setProgress(themed); } else if (holder.getItemViewType() == TYPE_WALLPAPERS) { WallpapersViewHolder wallpapersViewHolder = (WallpapersViewHolder) holder; wallpapersViewHolder.title.setText( String.format(mContext.getResources().getString(R.string.home_loud_wallpapers), Preferences.get(mContext).getAvailableWallpapersCount())); } }