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

The following examples show how to use androidx.recyclerview.widget.GridLayoutManager#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: GridPaddingItemDecorationBuilder.java    From recyclerview-adapters with Apache License 2.0 6 votes vote down vote up
@Override
public void getItemOffsets(final Rect outRect, final View view, final RecyclerView parent, final RecyclerView.State state) {
    final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();

    if (!(params instanceof GridLayoutManager.LayoutParams)) return;

    final GridParams gridParams = GridParams.create(view);
    if (gridParams == null) return;

    final int position = gridParams.getPosition();
    final int spanSize = gridParams.getSpanSize();
    final int index = gridParams.getSpanIndex();

    if (spanSize < 1 || index < 0) return;
    if (!usePadding(position)) return;

    boolean useVerticalPadding = paddingType.equals(PaddingType.BOTH) || paddingType.equals(PaddingType.VERTICAL);

    outRect.top = useVerticalPadding ? padding / 2 : 0;
    outRect.bottom = useVerticalPadding ? padding / 2 : 0;
    outRect.left = getPaddingLeft(index, spanSize);
    outRect.right = getPaddingRight(index, spanSize);
}
 
Example 2
Source File: ColorViewAdapter.java    From colorpicker with Apache License 2.0 6 votes vote down vote up
public ViewHolder(View v) {
    super(v);
    //buttons settings
    colorItem = v.findViewById(R.id.color);
    colorItem.setTextColor(tickColor);
    colorItem.setBackgroundResource(buttonDrawable);
    colorItem.setOnClickListener(this);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) colorItem.getLayoutParams();
    layoutParams.setMargins(marginButtonLeft, marginButtonTop, marginButtonRight, marginButtonBottom);
    if (buttonWidth != -1)
        layoutParams.width = buttonWidth;
    if (buttonHeight != -1)
        layoutParams.height = buttonHeight;

    //relative layout settings
    LinearLayout linearLayout = v.findViewById(R.id.linearLayout);
    GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) linearLayout.getLayoutParams();
    lp.setMargins(marginLeft, marginTop, marginRight, marginBottom);
}
 
Example 3
Source File: LauncherAdapter.java    From candybar with Apache License 2.0 5 votes vote down vote up
ViewHolder(View itemView, int viewType) {
    super(itemView);
    if (viewType == TYPE_HEADER) {
        name = itemView.findViewById(R.id.name);
        holderId = TYPE_HEADER;
    } else if (viewType == TYPE_CONTENT) {
        icon = itemView.findViewById(R.id.icon);
        name = itemView.findViewById(R.id.name);
        container = itemView.findViewById(R.id.container);

        MaterialCardView card = itemView.findViewById(R.id.card);
        if (CandyBarApplication.getConfiguration().getApplyGrid() == CandyBarApplication.GridStyle.FLAT) {
            if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
                card.setRadius(0f);
                card.setUseCompatPadding(false);
                int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
                GridLayoutManager.LayoutParams params = (GridLayoutManager.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);
        }

        holderId = TYPE_CONTENT;

        container.setOnClickListener(this);
    }
}
 
Example 4
Source File: SpaceItemDecoration.java    From YcShareElement with Apache License 2.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams) view.getLayoutParams();
    lp.topMargin = mSpace/2;
    lp.leftMargin = mSpace/2;
    lp.rightMargin = mSpace/2;
    lp.bottomMargin = mSpace/2;
}
 
Example 5
Source File: ClusterMapAdapter.java    From intra42 with Apache License 2.0 5 votes vote down vote up
void bind() {

            GridLayoutManager.LayoutParams paramsGridLayout = (GridLayoutManager.LayoutParams) itemView.getLayoutParams();
            if (paramsGridLayout == null)
                paramsGridLayout = new GridLayoutManager.LayoutParams(0, 0);
            paramsGridLayout.height = (int) baseItemHeight;
            paramsGridLayout.width = (int) baseItemWidth;

            itemView.setLayoutParams(paramsGridLayout);
        }
 
Example 6
Source File: ClusterMapAdapter.java    From intra42 with Apache License 2.0 5 votes vote down vote up
void bind(Location location, int x, int y) {

            itemView.setBackgroundColor(context.getResources().getColor(R.color.colorClusterMapWall));

            GridLayoutManager.LayoutParams paramsGridLayout = (GridLayoutManager.LayoutParams) itemView.getLayoutParams();
            if (paramsGridLayout == null)
                paramsGridLayout = new GridLayoutManager.LayoutParams(0, 0);

            int paddingLeft = itemPadding2dp;
            int paddingTop = itemPadding2dp;
            int paddingRight = itemPadding2dp;
            int paddingBottom = itemPadding2dp;

            Location left = getPosition(x - 1, y);
            if (left != null && left.kind == Location.Kind.WALL)
                paddingLeft = 0;
            Location top = getPosition(x, y - 1);
            if (top != null && top.kind == Location.Kind.WALL)
                paddingTop = 0;
            Location right = getPosition(x + 1, y);
            if (right != null && right.kind == Location.Kind.WALL)
                paddingRight = 0;
            Location end = getPosition(x, y + 1);
            if (end != null && end.kind == Location.Kind.WALL)
                paddingBottom = 0;

            paramsGridLayout.height = (int) (baseItemHeight - paddingTop - paddingBottom);
            paramsGridLayout.width = (int) (baseItemWidth - paddingLeft - paddingRight);
            paramsGridLayout.setMargins(paddingLeft, paddingTop, paddingRight, paddingBottom);

            itemView.setLayoutParams(paramsGridLayout);

        }
 
Example 7
Source File: ArtistBioSingleton.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public ViewHolder(View itemView, boolean hasRelatedArtists) {
    super(itemView);

    bioText = itemView.findViewById(R.id.artist_bio_content);
    lfmButton = itemView.findViewById(R.id.artist_bio_lfm_link);
    lfmButton.setOnClickListener(this);

    if (hasRelatedArtists) {
        ((GridLayoutManager.LayoutParams) itemView.getLayoutParams()).bottomMargin = 0;
    }
}
 
Example 8
Source File: WallpapersAdapter.java    From candybar with Apache License 2.0 4 votes vote down vote up
ViewHolder(View itemView) {
    super(itemView);
    String viewStyle = mContext.getResources().getString(
            R.string.wallpaper_grid_preview_style);
    Point ratio = ViewHelper.getWallpaperViewRatio(viewStyle);

    image = itemView.findViewById(R.id.image);
    image.setRatio(ratio.x, ratio.y);

    card = itemView.findViewById(R.id.card);
    if (CandyBarApplication.getConfiguration().getWallpapersGrid() == CandyBarApplication.GridStyle.FLAT) {
        if (card.getLayoutParams() instanceof GridLayoutManager.LayoutParams) {
            card.setRadius(0f);
            card.setUseCompatPadding(false);
            int margin = mContext.getResources().getDimensionPixelSize(R.dimen.card_margin);
            GridLayoutManager.LayoutParams params = (GridLayoutManager.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);
    }

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

    if (mIsShowName) {
        name = itemView.findViewById(R.id.name);
        author = itemView.findViewById(R.id.author);
    }

    card.setOnClickListener(this);
    card.setOnLongClickListener(this);
}
 
Example 9
Source File: ClusterMapAdapter.java    From intra42 with Apache License 2.0 4 votes vote down vote up
void bind(Location location) {

            UsersLTE user;
            user = clusterData.getUserInLocation(location);
            this.location = location;

            textView.setVisibility(View.GONE);
            if (location.host == null) {
                imageViewContent.setImageResource(R.drawable.ic_missing_black_25dp);
                imageViewContent.setColorFilter(ContextCompat.getColor(context, R.color.colorClusterMapComputerColor), android.graphics.PorterDuff.Mode.SRC_IN);
            } else {
                imageViewContent.clearColorFilter();
                if (user != null) {
                    UserImage.setImageSmall(context, user, imageViewContent);
                    if (levelSelectedCursus != null && location.highlight) {
                        CursusUsers cursusUser = levelSelectedCursus.get(user.id);
                        if (cursusUser != null) {
                            textView.setVisibility(View.VISIBLE);
                            textView.setText(String.valueOf(cursusUser.level));
                        }
                    }
                } else {
                    imageViewContent.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_desktop_mac_black_custom));
                    imageViewContent.setColorFilter(ContextCompat.getColor(context, R.color.colorClusterMapComputerColor), android.graphics.PorterDuff.Mode.SRC_IN);
                }
            }

            GridLayoutManager.LayoutParams paramsGridLayout = (GridLayoutManager.LayoutParams) itemView.getLayoutParams();
            paramsGridLayout.height = (int) (baseItemHeight);
            paramsGridLayout.width = (int) (baseItemWidth);
            imageViewContent.setPadding(itemPadding1dp, itemPadding1dp, itemPadding1dp, itemPadding1dp);

            if (location.highlight) {

//                paramsGridLayout.height = (int) (baseItemHeight - itemPadding2dp * 2);
//                paramsGridLayout.width = (int) (baseItemWidth - itemPadding2dp * 2);

                imageViewContent.setPadding(itemPadding2dp, itemPadding2dp, itemPadding2dp, itemPadding2dp);

                TypedValue a = new TypedValue();
                context.getTheme().resolveAttribute(android.R.attr.windowBackground, a, true);
                imageViewContent.setBackgroundResource(a.resourceId);

                imageViewContent.setBackgroundColor(ThemeHelper.getColorAccent(context));
            }
            itemView.setLayoutParams(paramsGridLayout);
        }
 
Example 10
Source File: GridPaddingItemDecorationBuilder.java    From recyclerview-adapters with Apache License 2.0 4 votes vote down vote up
public static GridParams create(View view) {
    return view.getLayoutParams() instanceof GridLayoutManager.LayoutParams ? new GridParams((GridLayoutManager.LayoutParams) view.getLayoutParams()) : null;
}
 
Example 11
Source File: GridPaddingItemDecorationBuilder.java    From recyclerview-adapters with Apache License 2.0 4 votes vote down vote up
public GridParams(GridLayoutManager.LayoutParams params) {
    position = params.getViewAdapterPosition();
    spanIndex = params.getSpanIndex();
    spanSize = params.getSpanSize();
}