如何在简单的布局中创建波纹效果 [英] How to create ripple effect in simple layout

查看:121
本文介绍了如何在简单的布局中创建波纹效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在触摸简单的线性/相对布局时,如何在其上产生波纹效果?

How can I have a ripple effect in a simple linear/relative layout when touching the layout?

我尝试将版式的背景设置为类似的内容:

I've tried setting the background of a layout to something like:

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

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

</ripple>

但是,当我触摸版面时,我只会看到纯白色的背景并且没有波纹效果.我在做什么错了?

However I'm only seeing a plain white background and no ripple effect when touching the layout. What am I doing wrong?

作为参考,这是我的布局xml文件:

For reference, here is my layout xml file:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="@drawable/test"
        android:clickable="true">
    </RelativeLayout>

推荐答案

事实证明这按预期工作.标准Material主题colorControlHighlight值为#40ffffff.因此,在白色背景上,这不会显示.将突出显示颜色更改为其他颜色,和/或更改对象的背景颜色.

It turns out this is working as intended. The standard Material theme colorControlHighlight value is #40ffffff. So on a white background, this will not show up. Changing the highlight color to something else works, and/or changing the background color of the object.

感谢所有人(特别是Alanv向我指出正确的方向).

Thanks all (especially Alanv for pointing me in the right direction).

这篇关于如何在简单的布局中创建波纹效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆