Debug完成圖:
Debug完成圖
昨天晚上開始學(xué)一下這個揭露動畫灿椅,準(zhǔn)備用在項目中做一個轉(zhuǎn)場钞支,啃完了API之后開始寫個小demo烁挟,距離跑成功一步之遙的當(dāng)兒撼嗓,出了個bug静稻,就怎么點擊按鈕都沒用振湾。
首先上bug圖:
bug:怎么點擊按鈕都沒用押搪,每點擊一次都會出現(xiàn)下面的報錯(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沒有設(shè)置顏色啊。遣钳。好的試了一下耍贾,果然是荐开,可以說是很鬼畜了。百侧。
layout.xml里邊的View控件改成下面這樣子能扒,再次運行程序就成了(發(fā)現(xiàn)2040還是會報錯初斑,但是動畫算是完美跑出來了见秤,所以小伙伴們這里記得設(shè)置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"/>
效果圖如下: