揭露动画(Reveal Effect)实现时的注意事项(附上bug-logcat)

简介: Debug完成图:Debug完成图昨天晚上开始学一下这个揭露动画,准备用在项目中做一个转场,啃完了API之后开始写个小demo,距离跑成功一步之遥的当儿,出了个bug,就怎么点击按钮都没用。

Debug完成图:

img_e7c47f3bff9d777d96c725316bea4902.gif
Debug完成图

昨天晚上开始学一下这个揭露动画,准备用在项目中做一个转场,啃完了API之后开始写个小demo,距离跑成功一步之遥的当儿,出了个bug,就怎么点击按钮都没用。

首先上bug图:

img_7137b4e15d552b3619f132ef1f144063.png

bug:怎么点击按钮都没用,每点击一次都会出现下面的报错(2040):

11-07 19:20:49.665 2454-2454/? I/Finsky: [1] com.google.android.finsky.services.j.a(149): Installation state replication succeeded.
11-07 19:20:49.711 7448-7448/? E/hei: 2040
11-07 19:20:49.718 1350-1371/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 5613338 , only wrote 5613120
11-07 19:20:50.376 7448-7448/? E/hei: 2040
11-07 19:20:50.992 7448-7448/? E/hei: 2040
11-07 19:20:51.591 7448-7448/? E/hei: 2040
11-07 19:20:54.790 1350-1372/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 6098164 , only wrote 5856480
11-07 19:20:58.322 7448-7448/? E/hei: 2040
11-07 19:20:58.328 1350-1371/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 5856667 , only wrote 5856480
11-07 19:21:01.540 1350-1372/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 6162708 , only wrote 6010560

activity.java全文:

package com.lwp.justtest;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewAnimationUtils;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    boolean flag = false;
    FloatingActionButton fab;
    private View mPuppet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPuppet = findViewById(R.id.view_puppet);
        fab = (FloatingActionButton)findViewById(R.id.fab);
        fab.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        doRevealAnimation();
    }

    private void doRevealAnimation() {
        int[] vLocation = new int[2];
        fab.getLocationInWindow(vLocation);
        int centerX = vLocation[0] + fab.getMeasuredWidth() / 2;
        int centerY = vLocation[1] + fab.getMeasuredHeight() / 2;

        int height = mPuppet.getHeight();
        int width = mPuppet.getWidth();
        int maxRradius = (int) Math.hypot(height, width);
        Log.e("hei", maxRradius + "");

        if (flag) {
            Animator animator = ViewAnimationUtils.createCircularReveal(mPuppet, centerX, centerY, maxRradius, 0);
            animator.setDuration(1000);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mPuppet.setVisibility(View.GONE);
                }
            });
            animator.start();
            flag = false;
        } else {
            Animator animator = ViewAnimationUtils.createCircularReveal(mPuppet, centerX, centerY, 0, maxRradius);
            animator.setDuration(1000);
            animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                    mPuppet.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            animator.start();
            flag = true;
        }
    }

}

layout.xml全文:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context="com.lwp.justtest.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:layout_gravity="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view_puppet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        android:backgroundTint="@color/colorPrimary"
        android:src="@drawable/map"
        app:pressedTranslationZ="10dp" />

</FrameLayout>

观众朋友们,这个看出毛病了吗。

我想了一下,额,会不会我的View没有设置颜色啊。。好的试了一下,果然是,可以说是很鬼畜了。。

layout.xml里边的View控件改成下面这样子,再次运行程序就成了(发现2040还是会报错,但是动画算是完美跑出来了,所以小伙伴们这里记得设置android:background以及android:visibility噢):

    <View
        android:id="@+id/view_puppet"
        android:background="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"/>

效果图如下:

img_e7c47f3bff9d777d96c725316bea4902.gif

目录
相关文章
|
6月前
|
图形学 Android开发
小功能⭐️Unity调用Android常用事件
小功能⭐️Unity调用Android常用事件
|
9月前
|
JSON API 数据格式
dragonBones5.6.300解析关键帧的actions异常的bug
dragonBones5.6.300解析关键帧的actions异常的bug
88 0
|
API Android开发
揭露动画(Reveal Effect)实现时的注意事项(附上bug-logcat)
揭露动画(Reveal Effect)实现时的注意事项(附上bug-logcat)
|
程序员 Android开发 Java
Android Studio "佛祖保佑 永无bug" 注释模板设置详解(仅供娱乐)
1、注释模板效果图 今天在网上看到一段有趣的注释,佛祖保佑 永无bug, 效果如下图所示: 代码如下所示: /** * _ooOoo_ * o8888888o * 88" .
2182 0
|
API Android开发 Kotlin
Android进阶设计 | 使用揭露动画(Reveal Effect)做一个丝滑的Activity转场动画
Android进阶设计 | 使用揭露动画(Reveal Effect)做一个丝滑的Activity转场动画
|
XML 消息中间件 编解码
Android开发(第一行代码 第二版) 常见异常和解决办法(基于Android Studio)(二)
在自定义Dialog的时候,用Glide加载图片时报了一下异常 Caused by: java.lang.IllegalArgumentException: You must pass in a non null View 原因是Dialog还未显示出来,而ImageView为null,所以报了这个异常 解决的方法是先把Dialog显示出来,mDialog.show();在去用Glide加载图片。
|
存储 定位技术 API
android退出程序代码!Android开发究竟该如何学习,实战篇
android退出程序代码!Android开发究竟该如何学习,实战篇
android退出程序代码!Android开发究竟该如何学习,实战篇
|
XML Android开发 数据格式
实战 | 使用揭露动画(Reveal Effect)做一个丝滑的Activity转场动画
提笔之际(附总体思路) 最近跟几个小伙伴在实践一个项目,考虑到界面效果,我们决定使用揭露动画作为Activity的转场动画。 这里主要是我负责这部分的实现。
1547 0
|
Android开发 UED 数据安全/隐私保护
Android项目实战(四十二):启动页优化,去除短暂白屏或黑屏
原文:Android项目实战(四十二):启动页优化,去除短暂白屏或黑屏   大家会发现一个空项目,从手机桌面打开app是秒启动。但是对于自己开发的项目,有时会发现打开app的时候,会有短暂的1秒--2秒的白屏或者黑屏,然后才进入到程序界面。
1463 0