ImageView selectableItemBackgroundBorderless does not render outside of view bounds

后端 未结 6 2210
青春惊慌失措
青春惊慌失措 2021-02-13 21:47

I am using selectableItemBackgroundBorderless to add a ripple to an ImageView. My expected behaviour would be to have a circular ripple, extending the

相关标签:
6条回答
  • 2021-02-13 22:05

    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.

    0 讨论(0)
  • 2021-02-13 22:09

    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:

    0 讨论(0)
  • 2021-02-13 22:15

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

    0 讨论(0)
  • 2021-02-13 22:21

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

    0 讨论(0)
  • 2021-02-13 22:22

    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"
                />
    
    0 讨论(0)
  • 2021-02-13 22:24

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

    0 讨论(0)
提交回复
热议问题