【问题标题】:How to achieve an "overflowing" riplle-effect in android如何在android中实现“溢出”涟漪效应
【发布时间】:2018-08-22 11:53:27
【问题描述】:

我在 YouTube 的安卓应用中看到了这种涟漪效应。我想在我的应用程序中获得相同的效果。我应该创建自己的 Ripple-Drawable 还是有不同的方法? 实际上我已经尝试过“?attr/selectableItemBackground”,但效果却大不相同。

这是我的涟漪效果的样子:

【问题讨论】:

  • 这是由 Material Design 通过 AppCompat 主题处理的。在这里了解这些:android-developers.googleblog.com/2014/10/…
  • @shkschneider 谢谢。我想我已经发现了我的问题。
  • 如果是这样,请不要犹豫回答您自己的问题并验证它;)
  • 尝试使用android:background="?attr/selectableItemBackgroundBorderless"
  • @shkschneider 希望我的答案很快就会上线。

标签: java android ripple rippledrawable


【解决方案1】:

您可以从选择器创建波纹。请参见下面的示例。

1.这是API 21及以上版本,在drawable中创建

custom_ripple.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
    <shape android:shape="rectangle">
        <solid android:color="@color/line" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/transparent" />
    </shape>
</item>
</selector>

2.在drawable-v21中为以下21 API添加同名文件。

v1/custom_ripple.xml

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

<item
    android:id="@android:id/mask"
    android:drawable="@android:color/white" />
</ripple>

最后设置 android:background="@drawable/custom_ripple" ,你想要波纹。

【讨论】:

    【解决方案2】:

    只需将值 ?android:selectableItemBackgroundBorderless 添加到 android:foregroundandroid:background

    请务必使用 android 命名空间。

    【讨论】:

      猜你喜欢
      • 2015-07-03
      • 2015-02-11
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      相关资源
      最近更新 更多