Android L-在视图上播放波纹效果 [英] Android L -- Play Ripple Effect on View

查看:111
本文介绍了Android L-在视图上播放波纹效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在特定时间(而不是在被触摸的视图上)在视图上播放涟漪效果(来自Android L). 具体来说,当用户成功更改某些文本时,我希望某个视图发挥绿色波纹效果以显示成功.有什么办法吗?

I am trying to play a ripple effect (from Android L) on a view at a certain time (not on the view being touched). To be specific, when the user successfully changes some text, I want a certain view to play a green ripple effect to show success. Is there any way to do this?

我尝试将RippleDrawable放入动画中,并将RippleDrawable用作成功视图"的背景.但是,我无法弄清我所描述的如何播放涟漪动画.

I have tried putting a RippleDrawable in an Animation, putting the RippleDrawable as the background for my "success view." But, I can't figure out how to play the ripple animation as I have described.

P.S.我的项目目前仅是Android L,因此我不担心向后兼容性.

P.S. My project is Android L only right now, so I am not worried about backwards compatibility.

推荐答案

由于蒙版只是一个实心矩形,因此可以将波纹XML简化为:

Since your mask is just a solid rectangle, you can simplify your ripple XML to:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item android:id="@android:id/mask" android:drawable="@android:color/white" />
    <item android:drawable="@drawable/file_item_selector"/>
</ripple>

您可以通过强制视图进入和退出按下状态来手动触发波纹效果.

You can manually trigger a ripple effect by forcing a view in and out of the pressed state.

myView.setPressed(true);

// For a quick ripple, you can immediately set false.
myView.setPressed(false);

// Or for a long ripple, you can post to a handler.
myView.postDelayed(new Runnable() {
    public void run() {
        myView.setPressed(false);
    }
}, 500 /* delay in milliseconds */);

这篇关于Android L-在视图上播放波纹效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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