Android Material Design(6) CircularReveal圆形扩散动画的使用

来源:互联网 发布:天龙八部发色数据女生 编辑:程序博客网 时间:2024/05/18 17:24

效果图:


项目依赖:

 compile 'com.android.support:appcompat-v7:23.2.1'    compile 'com.android.support:design:23.2.1'    compile 'com.android.support:cardview-v7:23.2.1'

布局文件:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.imgod.md_5.MainActivity">    <android.support.v7.widget.CardView        android:id="@+id/cardview_1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        app:cardCornerRadius="10dp"        android:colorControlHighlight="#ff6600"        app:cardElevation="10dp">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_margin="20dp"            android:text="@string/hello"            android:textColor="#ff6600" />    </android.support.v7.widget.CardView></RelativeLayout>

Activity:

package com.example.imgod.md_5;import android.animation.Animator;import android.os.Build;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.support.v7.widget.CardView;import android.view.View;import android.view.ViewAnimationUtils;import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener {    private CardView cardview_1;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initView();        initEvent();    }    private void initEvent() {        cardview_1.setOnClickListener(this);    }    private void initView() {        cardview_1 = (CardView) findViewById(R.id.cardview_1);    }    @Override    public void onClick(View v) {        switch (v.getId()) {            case R.id.cardview_1:                startAnimation(cardview_1);                break;        }    }    private void startAnimation(View view) {        //因为CircularReveal动画是api21之后才有的,所以加个判断语句,免得崩溃        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            int cicular_R = view.getHeight() / 2 > view.getWidth() / 2 ? view.getHeight() / 2 : view.getWidth() / 2;            Animator animator = ViewAnimationUtils.createCircularReveal(view, (int) view.getWidth() / 2, (int) view.getHeight() / 2, 0, cicular_R);            animator.setDuration(1000);            animator.start();        } else {            Toast.makeText(this, "SDK版本太低,请升级", Toast.LENGTH_SHORT).show();        }    }}

源码非常简单,就是通过createCircularReveal方法根据5个参数来创建一个RevealAnimator动画对象。

这五个参数分别是:
view 操作的视图
centerX 动画开始的中心点X
centerY 动画开始的中心点Y
startRadius 动画开始半径
startRadius 动画结束半径
不过网上说android:colorControlHighlight:设置波纹颜色

这个属性是设置波纹颜色的.但是我设置了却没有效果.百思不得姐,有知道的希望不吝赐教下哈.感激不尽

源码地址:https://github.com/imgod1/Md_5

0 0
原创粉丝点击