Android Chip with material font icon text not wrapping correctly

49 Views Asked by At

In my Android app I have a recyclerview with chips inside, and some chip has not just normal text but icons from the material font.

@Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
    ...
    ...
    Chip chip=(Chip)holder.mIdView;
    chip.setTypeface(materialFont);
    chip.setText("shopping_cart_checkout"); //just an icon with a long name
    ...
    ...
    
    }

What I am experiencing is that the chip's horizontal size depends on the name string length and not on the icon width.

I would expect that the chip wraps around the icon, but it wraps around the text instead, no matter what padding I set (I checked many SO answers about those kind of settings).

If I add many spaces after the icon name the size increases. Short icon names yield short chips, while long names yield long chips.

I think it is wrapping around the simple text of the name, not the real displayed "string" (the font is different so the icon is like a string).

What can I do to make the chips wrap around the displayed icon?

1

There are 1 best solutions below

0
P5music On

I possible workaround that worked for me is:

holder.mIdView.setMaxWidth(Math.round(holder.mIdView.getChipIconSize()*3));