Java Code Examples for androidx.recyclerview.widget.StaggeredGridLayoutManager#LayoutParams

The following examples show how to use androidx.recyclerview.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: AssemblyItemFactory.java    From assembly-adapter with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Item<DATA> dispatchCreateItem(@NonNull ViewGroup parent) {
    @NonNull
    Item<DATA> item = createAssemblyItem(parent);

    if (fullSpanInStaggeredGrid) {
        ViewGroup.LayoutParams layoutParams = item.getItemView().getLayoutParams();
        if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
            ((StaggeredGridLayoutManager.LayoutParams) layoutParams).setFullSpan(true);
            item.getItemView().setLayoutParams(layoutParams);
        }
    }

    item.onInit(parent.getContext());

    Item<DATA> finalItem = inRecycler ? new RecyclerItemWrapper<>(item) : item;

    registerListeners(finalItem);

    return finalItem;
}
 
Example 2
Source File: SpacesItemWithHeadDecoration.java    From Pixiv-Shaft with MIT License 6 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

    outRect.bottom = space;

    int position = parent.getChildAdapterPosition(view);


    StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
    if (params.getSpanIndex() % 2 != 0) {
        //右边
        outRect.left = space / 2;
        outRect.right = space;
    } else {
        //左边
        outRect.left = space;
        outRect.right = space / 2;
    }

    if (position == 0) {
        outRect.top = 0;
        outRect.right = 0;
        outRect.left = 0;
    }
}
 
Example 3
Source File: PostFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent,
                           @NonNull RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);

    StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();

    int spanIndex = layoutParams.getSpanIndex();

    int halfOffset = mItemOffset / 2;

    if (spanIndex == 0) {
        outRect.set(0, 0, halfOffset, 0);
    } else {
        outRect.set(halfOffset, 0, 0, 0);
    }
}
 
Example 4
Source File: RcvMultiAdapter.java    From RecyclerViewAdapter with Apache License 2.0 6 votes vote down vote up
/**
 * 添加HeadView或FootView或LoadMore或EmptyView后
 * 兼容StaggeredGridLayoutManager的方法
 */
@Override
public void onViewAttachedToWindow(RcvHolder holder)
{
    super.onViewAttachedToWindow(holder);
    if (isInHeadViewPos(holder.getLayoutPosition())
            || isInFootViewPos(holder.getLayoutPosition())
            || isInLoadMorePos(holder.getLayoutPosition())
            || isInEmptyStatus())
    {
        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: BrickRecyclerAdapter.java    From brickkit-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(BrickViewHolder holder, int position) {
    BaseBrick baseBrick = dataManager.brickAtPosition(position);
    if (baseBrick != null) {
        if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
            if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
                ((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(
                        baseBrick.getSpanSize().getSpans(recyclerView.getContext()) == dataManager.getMaxSpanCount());
            }
        }

        if (baseBrick.isDataReady()) {
            baseBrick.onBindData(holder);
        } else {
            baseBrick.onBindPlaceholder(holder);
        }
        if (onReachedItemAtPosition != null) {
            onReachedItemAtPosition.bindingItemAtPosition(position);
        }
    }
}
 
Example 6
Source File: ExpandableAdapter.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(@NonNull VH holder) {
    if (isParentItem(holder.getAdapterPosition())) {
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
        if (lp instanceof StaggeredGridLayoutManager.LayoutParams) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams)lp;
            p.setFullSpan(true);
        }
    }
}
 
Example 7
Source File: RequestAdapter.java    From candybar with Apache License 2.0 5 votes vote down vote up
@Nullable
private StaggeredGridLayoutManager.LayoutParams getLayoutParams(@Nullable View view) {
    if (view != null) {
        try {
            return (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
        } catch (Exception e) {
            LogUtil.d(Log.getStackTraceString(e));
        }
    }
    return null;
}
 
Example 8
Source File: AdapterWrapper.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
    if (isHeaderOrFooter(holder)) {
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
        if (lp instanceof StaggeredGridLayoutManager.LayoutParams) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams)lp;
            p.setFullSpan(true);
        }
    } else {
        mAdapter.onViewAttachedToWindow(holder);
    }
}
 
Example 9
Source File: GridItemDecoration.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    final int position = parent.getChildAdapterPosition(view);
    final StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();

    if (adapter.getItemViewType(position) == ItemAdapter.TYPE_SECTION) {
        lp.setFullSpan(true);
    } else {
        final int spanIndex = lp.getSpanIndex();

        if (position >= 0) {
            // First row gets some spacing at the top
            if (position < spanCount && position < adapter.getFirstPositionOfViewType(ItemAdapter.TYPE_SECTION)) {
                outRect.top = gutter;
            }

            // First column gets some spacing at the left and the right side
            if (spanIndex == 0) {
                outRect.left = gutter;
            }

            // All columns get some spacing at the bottom and at the right side
            outRect.right = gutter;
            outRect.bottom = gutter;
        }
    }
}
 
Example 10
Source File: RcvSectionMultiLabelAdapter.java    From RecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(RcvHolder holder)
{
    if (isSectionLabelViewType(holder.getItemViewType()))
    {
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
        if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams)
        {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
            p.setFullSpan(true);
        }
    }
    super.onViewAttachedToWindow(holder);
}
 
Example 11
Source File: RecyclerViewItem.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
private void fullSpan(boolean fullspan) {
    if (mView != null) {
        StaggeredGridLayoutManager.LayoutParams layoutParams =
                new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setFullSpan(fullspan);
        mView.setLayoutParams(layoutParams);
    }
}
 
Example 12
Source File: GroupedRecyclerViewAdapter.java    From GroupedRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
private void handleLayoutIfStaggeredGridLayout(RecyclerView.ViewHolder holder, int position) {
    if (isEmptyPosition(position) || judgeType(position) == TYPE_HEADER || judgeType(position) == TYPE_FOOTER) {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams)
                holder.itemView.getLayoutParams();
        p.setFullSpan(true);
    }
}
 
Example 13
Source File: GroupedRecyclerViewAdapter.java    From GroupedRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
private boolean isStaggeredGridLayout(RecyclerView.ViewHolder holder) {
    ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
    if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
        return true;
    }
    return false;
}
 
Example 14
Source File: RecyclerViewItem.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void fullSpan(boolean fullspan) {
    if (mView != null) {
        StaggeredGridLayoutManager.LayoutParams layoutParams =
                new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setFullSpan(fullspan);
        mView.setLayoutParams(layoutParams);
    }
}
 
Example 15
Source File: BaseRecyclerAdapter.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(K holder) {
    super.onViewAttachedToWindow(holder);
    int position = holder.getAdapterPosition();
    int type = getItemViewType(position);
    if (isFullSpanType(type)) {
        ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
        if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) {
            StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) layoutParams;
            lp.setFullSpan(true);
        }
    }
}
 
Example 16
Source File: HomeScreenAdapter.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void bindHeader(HeaderViewHolder headerHolder) {
    StaggeredGridLayoutManager.LayoutParams layoutParams =
            (StaggeredGridLayoutManager.LayoutParams)headerHolder.itemView.getLayoutParams();
    layoutParams.setFullSpan(true);

    boolean noCustomBanner =
            !CustomBanner.useCustomBanner(context, screenHeight, screenWidth, headerHolder.headerImage, CustomBanner.Banner.HOME);
    if (noCustomBanner) {
        headerHolder.headerImage.setImageResource(R.drawable.commcare_logo);
    }
}
 
Example 17
Source File: IAdapterWithHeadView.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
    if (lp instanceof StaggeredGridLayoutManager.LayoutParams
            && holder.getLayoutPosition() == 0) {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
        p.setFullSpan(true);
    }
}
 
Example 18
Source File: BookAdapter.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 处理 StaggeredGridLayoutManager 添加头尾布局占满屏幕宽的情况
 */
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    super.onViewAttachedToWindow(holder);
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
    if (lp != null
            && lp instanceof StaggeredGridLayoutManager.LayoutParams
            && (isHeader(holder.getLayoutPosition()) || isFooter(holder.getLayoutPosition()))) {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
        p.setFullSpan(true);
    }
}
 
Example 19
Source File: FollowingItemDecoration.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
                           @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);

    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager == null) {
        return;
    }

    FollowingAdapter adapter = (FollowingAdapter) parent.getAdapter();
    if (adapter == null) {
        return;
    }

    parentPaddingLeft = parent.getPaddingLeft();
    parentPaddingRight = parent.getPaddingRight();
    parentPaddingTop = parent.getPaddingTop();
    parentPaddingBottom = parent.getPaddingBottom();
    insets = getWindowInset(parent);
    if (parentPaddingLeft != insets.left
            || parentPaddingRight != insets.right
            || parentPaddingTop != 0
            || parentPaddingBottom != insets.bottom) {
        setParentPadding(parent, insets);
    }

    StaggeredGridLayoutManager.LayoutParams params
            = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();

    int spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
    int spanIndex = params.getSpanIndex();

    if (adapter.isPhotoItem(params.getViewAdapterPosition())) {
        if (spanCount == 1) {
            outRect.set(
                    marginSingleSpanPhoto.left,
                    0,
                    marginSingleSpanPhoto.right,
                    marginSingleSpanPhoto.bottom
            );
        } else {
            if (spanIndex == 0) {
                outRect.set(marginGridItem, 0, marginGridItem, marginGridItem);
            } else {
                outRect.set(0, 0, marginGridItem, marginGridItem);
            }
        }
    }
}
 
Example 20
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 3 votes vote down vote up
/**
 * When set to true, the item will layout using all span area. That means, if orientation
 * is vertical, the view will have full width; if orientation is horizontal, the view will
 * have full height.
 * if the hold view use StaggeredGridLayoutManager they should using all span area
 *
 * @param holder True if this item should traverse all spans.
 */
protected void setFullSpan(RecyclerView.ViewHolder holder) {
    if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
        StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) holder
                .itemView.getLayoutParams();
        params.setFullSpan(true);
    }
}