第一部分:.Meterial Design自带水波纹介绍,支持Android 5.0以上,介绍的是自带的水波纹效果,水波纹效果跟主题有关。先看简单效果:
布局文件的代码如下:
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:text="@string/app_name" />
<Button
android:layout_marginTop="10dp"
android:layout_width="200dp"
android:layout_height="60dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:text="@string/app_name" />
<Button
android:layout_marginTop="10dp"
android:layout_width="200dp"
android:layout_height="60dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/app_name" />
注意:1.默认的按钮背景颜色和水波纹颜色都被修改了,可以再主题里面自定义颜色。
2.注意后面两个按钮的水波纹效果,分别是外接圆和内切圆
//更改点击水波纹效果颜色
<item name="android:colorControlNormal">@android:color/holo_blue_light</item>
//更改长按水波纹效果
<item name="android:colorControlHighlight">@android:color/holo_blue_dark</item>
//更改按钮默认的背景颜色
<item name="android:colorButtonNormal">@android:color/holo_green_dark</item>
第二部分:reveal 效果,揭露动画
Meterial Design 自带效果非常酷炫,从效果上来说,Android 5.0在UI上简直是质的飞跃,先看效果图,模拟器有点卡,实际效果是酷毙了
改变起始点坐标后的效果
主要代码和参数解释如下:
/**
* @param view 目标view.
* @param centerX
* @param centerY
* @param startRadius The starting radius of the animating circle.
* @param endRadius The end
*/
//这个方法的参数意思算是见名知意
int centerX = content.getWidth() / 2;
int centerY = content.getHeight() / 2;
float startRaius = 0.0f;
float endRadius = (float) Math.hypot(centerX * 1.0, centerY * 1.0);//勾股定理
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Animator animator = ViewAnimationUtils.createCircularReveal(content, centerX, centerY, startRaius, endRadius);
animator.setInterpolator(new AccelerateInterpolator());
animator.setDuration(1500);
animator.start();
}