Android: programmatically set the corner radius of rippledrawable

I tried to create a segmented button control and used a paintable control for each segment

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="@color/search_filters_selected" />
        </shape>
    </item>
    <item>
        <shape
            android:padding="10dp"
            android:shape="rectangle">
            <solid android:color="@color/search_filters_unselected" />
            <stroke
                android:width="1dp"
                android:color="@color/search_filters_selected" />
        </shape>
    </item>
</ripple>

Then, use setcornerradii to set the corner radius to left fillet, right fillet or no fillet, depending on whether it is the first, the last or the middle

The problem is that I try to show the ripple effect in the view, but I can't do this, so that the ripple effect is limited by the fillet, and it is always drawn on the original rectangle like this

I try to set the same corner radius as the mask of rippledrawable, or use < item Android: drawable = ""? Android: selectableitembackground "/ > in the layer list instead of < ripple >, but the result is the same. Who knows how to do this so that the ripple is limited to the new boundary?

resolvent:

The solution, if useful to anyone, is to use ripples without masks, but also set the corner radius (any one will be updated later)

So I use

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#625505" />
            <corners android:radius="1dp"/>
        </shape>
    </item>
    <item>
        <shape
            android:padding="10dp"
            android:shape="rectangle">
            <solid android:color="@color/search_filters_selected" />
            <stroke
                android:width="1dp"
                android:color="@color/search_filters_selected" />
        </shape>
    </item>
</ripple>

Finally let it work

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>