首页 > 解决方案 > 如何在 android 中显示类似 YouTube 的涟漪效应?

问题描述

安卓上最新版本的 YouTube 应用程序显示了一个非常不同的涟漪。

那就是当我们将手指从按钮上抬起时,然后在结束波纹时它显示出中风。

如何在android中实现这种类型的涟漪?

当我们抬起手指时,波纹的末端有一个笔触。

标签: androidrippledrawableripple-effect

解决方案


通过设置它实际上只是一个波纹背景android:background="?selectableItemBackground"

在 Youtube 按钮示例中,

<RelativeLayout
    android:id="@+id/rl_chat_search"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?selectableItemBackground"  <-- ripple effect
    android:layout_margin="10dp">

    <ImageView
        android:src="@drawable/ic_download"

    />

    <TextView
        android:text="Download"
      />
</RelativeLayout>

推荐阅读