ImageView selectableItemBackgroundBorderless does not render outside of view bounds

喜你入骨 提交于 2019-12-04 03:33:45

If you have a clickable ImageView, then most possibly it should be an ImageButton instead.

Having defined following ImageButton:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackgroundBorderless"
    app:srcCompat="@drawable/ic_navigation_black_24dp" />

Then you'll get following output:

If you want bigger ripple effect, you have to change view's size: instead of wrap_content make it, let's say, 100dp:

Define ripple_effect_circle.xml in drawable

<?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="#BDBDBD"
    >

    <item android:id="@android:id/mask">
        <shape android:shape="oval">
            <size
                android:width="60dp"
                android:height="60dp"/>
            <solid android:color="#BDBDBD" />
        </shape>
    </item>

</ripple>

Define ImageView in layout

    <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="60dp"
            android:src="@drawable/ripple_effect_circle"
            android:background="@drawable/your_round_image"
            />

You can use library https://github.com/hdodenhof/CircleImageView for this issue.

Create the circular Imageview with the above library and it will be having the ripple effect as you expected.

One thing is your limiting the height of the ImageView by 46dp add padding to ImageView instead of Parent layout

do layerlist drawable xml make the first item shape circle then add item selectableItemBackgroundBorderless and it will work fine

Just change from using ImageView's foreground to background: android:background="?selectableItemBackgroundBorderless". Then you should see the ripple render outside of the view bounds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!