创建不透明的可绘制波纹 [英] Create a ripple drawable without transparency

查看:140
本文介绍了创建不透明的可绘制波纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何正确使用Ripple Drawable感到迷茫.

I'm a bit lost about how to properly use Ripple Drawable.

假设我有这个可绘制对象:

Let's say I have this drawable :

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
     <item android:state_pressed="false" android:state_focused="true" android:drawable="@color/accent_color_light" />
     <item android:state_pressed="true" android:drawable="@color/accent_color_light" />
     <item android:drawable="@android:color/white" />
</selector>

所以它是纯白色背景,当聚焦或按下时会变成浅蓝色.

So it is a plain white background which changes to a light blue when it is focused or pressed.

如何获得相同的颜色但具有波纹效果? 我想我需要使用遮罩来防止其超出视图范围?

How can I get the same colors but with a ripple effect ? I think I need to use a mask to prevent it from getting outside the bounds of the view ?

推荐答案

忘记回答我自己的问题.

Forgot to answer my own question.

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

   <item android:id="@android:id/mask">
       <shape android:shape="rectangle" >
           <solid android:color="@android:color/holo_green_light" />
       </shape>
    </item>

</ripple>

不显示ID为"mask"的项目中的颜色.它用于区分纹波效果的形状和界限.没有它,它可能会超出视图范围.

The color in the item with the id "mask" is not displayed. It is used to tell the shape and bounds of the ripple effect. Without it, it can go outside the bounds of the view.

这篇关于创建不透明的可绘制波纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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