ImageView selectableItemBackgroundBorderless不呈现在视图范围之外 [英] ImageView selectableItemBackgroundBorderless does not render outside of view bounds
问题描述
我正在使用selectableItemBackgroundBorderless
向ImageView
添加波纹.
我的预期行为是产生圆形波纹,从而扩展视图的大小.不幸的是,涟漪因视角范围而被裁剪.
该问题如何解决?
I am using selectableItemBackgroundBorderless
to add a ripple to an ImageView
.
My expected behaviour would be to have a circular ripple, extending the views size. Unfortunately the ripple gets cropped by the view bounds.
How can this issue be solved?
默认状态:
按下状态:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_instruction_container"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/nav_gradient_bg"
android:padding="20dp">
<ImageView
android:id="@+id/nav_sign"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:layout_centerVertical="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/nav_sign"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold"
android:maxLines="2"
tools:text="A644 Shudehill asdfkjasdf asdfasdf asdfsss"
android:ellipsize="marquee"
/>
<TextView
android:id="@+id/subTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/nav_sign"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:textColor="@color/white"
android:textSize="17sp"
tools:text="via Church St"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_nav_queue_sheet_icon_light"
android:id="@+id/nav_queue"
android:scaleType="centerInside"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:adjustViewBounds="true"/>
</RelativeLayout>
推荐答案
如果您具有可点击的ImageView
,则很有可能应该是ImageButton
.
If you have a clickable ImageView
, then most possibly it should be an ImageButton
instead.
已根据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:
如果想要更大的波纹效果,则必须更改视图的大小:代替wrap_content
使其变为100dp:
If you want bigger ripple effect, you have to change view's size: instead of wrap_content
make it, let's say, 100dp:
这篇关于ImageView selectableItemBackgroundBorderless不呈现在视图范围之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!