Android 中Layout实现点击水波纹特效

本文介绍如何为Android中的布局类如LinearLayout、RelativeLayout等实现点击时的水波纹效果。提供了三种实现方法:使用系统提供的ripple效果、第三方库及通过设置特定属性实现。并针对不同API版本给出了具体的实现方案。

Android5.0以后TextView,Button、TabLayout等控件默认都有点击水波纹效果,那布局类LinearLayout、RelativeLayout、TableLayout、FrameLayout、AbsoluteLayou如何实现

A:使用 ripple、API-21+。

B:三方库, RippleEffect或material-ripple

C:android:background=”?attr/selectableItemBackground”

建议使用方式3,使用的中需要注意以下:

1.view设置下面属性android:clickable=”true” android:focusable=”true”;

2.Layout实现View.OnClickListener();

3.API 7+ (Android + AppCompat Support Library):实现方式是:android:background=“?attr/selectableItemBackground”;

4.API 11+ (Pure Android):实现方式是:android:background=“android:attr/selectableItemBackground”;

以下是git三方库的地址:
https://github.com/balysv/material-ripple

https://github.com/CodingForAndroid/RippleEffect

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值