揭露动画(Reveal Effect)实现时的注意事项(附上bug-logcat)
Debug完成图:
昨天晚上开始学一下这个揭露动画,准备用在项目中做一个转场,啃完了API之后开始写个小demo,距离跑成功一步之遥的当儿,出了个bug,就怎么点击按钮都没用。
首先上bug图:
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"/>
效果图如下:
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
boolean java.lang.String.equals(java.lang.Object)' on a null object re...
APP中需要实现LayoutInflater布局加载器动态加载布局,然而开启程序一运行就闪退。。。 FATAL EXCEPTION: main Process: com.lwp.justtest, PID: 6054 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lwp.justtest/com.lwp.justtest.MainActivity}: android.view.InflateException: Binary XML file line #19: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThrea...
- 下一篇
21.Swift学习之扩展
扩展 为现有的类、结构体、枚举类型、协议添加了新功能。扩展和 Objective-C 中的分类类似。 扩展可以: 添加计算属性; 定义方法; 提供新的构造函数; 使现有的类型遵循某协议 Swift中使用extension关键字实现扩展 语法 extension SomeType { // new functionality to add to SomeType goes here } 扩展可以使已有的类型遵循一个或多个协议。在这种情况下,协议名的书写方式与类或结构体完全一样: extension SomeType: SomeProtocol, AnotherProtocol { // implementation of protocol requirements goes here } 扩展计算属性 扩展可以向已有的类型添加计算实例属性和计算类型属性。 extension Double { var km: Double { return self * 1_000.0 } var m: Double { return self } var cm: Double { return self...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Linux系统CentOS6、CentOS7手动修改IP地址
- Docker安装Oracle12C,快速搭建Oracle学习环境