我想在我的图标上产生涟漪效应。但是当我增加填充时,它会减小图标大小 当填充为5dp时,它看起来像这个
我的ImageView xml
<ImageView
android:id="@+id/institute_search_item_request_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="20dp"
android:layout_marginTop="15dp"
android:background="@drawable/request_institute_red_icon__shape"
android:foreground="@drawable/ripple_foreground"
android:padding="12dp"
android:src="@drawable/ic_link_white_24dp" />
request_institute_red_icon__shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorPrimary" />
和ripple_foreground.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorAccent">
<item android:id="@android:id/mask">
<shape android:shape="oval">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
答案 0 :(得分:0)
删除填充,它会缩小你的图标。
在你imageview
中只需添加此行即可获得涟漪效果
android:foreground="?attr/selectableItemBackground"
获得椭圆形波纹:
<强> round_background.xml 强>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/colorAccent"
android:radius="your_radius" // try radius
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="oval">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item android:drawable="@drawable/red_background" />
</ripple>
<强> red_background.xml 强>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/red_color"/>/>
</shape>