Android 为什么我的show方法在我的按钮到达后调用它';他原来的位置是什么?

Android 为什么我的show方法在我的按钮到达后调用它';他原来的位置是什么?,android,android-animation,circularreveal,viewpropertyanimator,Android,Android Animation,Circularreveal,Viewpropertyanimator,我是android新手,我尝试使用带按钮的circuler Reveal。所以,当我点击按钮时,它会移动到中心,然后圆圈从中心出来。 当我按下“后退”按钮时,圆圈显示开始,我的按钮移动到中心位置。直到这里,一切都很好。但是问题出现在第一次硝化后,没有点击按钮,圆圈再次出现??? package redblood.imf.animateParticlerViewonLayout; 导入android.animation.Animator; 导入android.animation.AnimatorL

我是android新手,我尝试使用带按钮的circuler Reveal。所以,当我点击按钮时,它会移动到中心,然后圆圈从中心出来。 当我按下“后退”按钮时,圆圈显示开始,我的按钮移动到中心位置。直到这里,一切都很好。但是问题出现在第一次硝化后,没有点击按钮,圆圈再次出现???

package redblood.imf.animateParticlerViewonLayout;
导入android.animation.Animator;
导入android.animation.AnimatorListenerAdapter;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.view;
导入android.view.ViewAnimationUtils;
导入android.view.ViewPropertyAnimator;
导入android.view.animation.Interpolator;
导入android.widget.ImageButton;
导入android.widget.ImageView;
公共类MainActivity扩展了AppCompatActivity{
图像按钮图像按钮;
图像视图图像视图;
//在这里,我们保存按钮的初始位置,以便我们可以再次访问
//搬家后
int buttonyninitial,buttonyninitial;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(imageView)findViewById(R.id.screenView);
imageView.setVisibility(视图.不可见);
imageButton=(imageButton)findViewById(R.id.imageButton);
imageButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
ButtonInitial=(int)v.getPivotX();
buttonYinitial=(int)v.getPivotY();
最终视图属性yanimator anim=v.animate().xBy((imageView.getWidth()/2)-20).yBy((imageView.getHeight()/2)-15).setDuration(1000);
anim.setListener(新的AnimatorListenerAdapter(){
AnimationEnd上的公共无效(Animator动画){
super.onAnimationEnd(动画);
显示(图像视图);
}
});
}
});
}
私人空间显示(视图){
int x=view.getWidth()/2;
int y=view.getHeight()/2;
int rad=Math.max(view.getWidth(),view.getHeight());
最终动画师anim=ViewAnimationUtils.createCircularVeal(视图,x,y,0,rad);
动画设定持续时间(1000);
view.setVisibility(view.VISIBLE);
anim.start();
}
//在这里,我是回布顿,所以当我回我的按钮可以去
//回到最初的位置
@凌驾
public void onBackPressed(){
隐藏(图像视图);
}
私有空心隐藏(图像视图){
int x=view.getWidth()/2;
int y=view.getHeight()/2;
int rad=Math.max(view.getWidth(),view.getHeight());
Animator anim=ViewAnimationUtils.createCircularVeal(视图,x,y,rad,0);
动画设定持续时间(1000);
anim.addListener(新的AnimatorListenerAdapter(){
@凌驾
AnimationEnd上的公共无效(Animator动画){
super.onAnimationEnd(动画);
imageView.setVisibility(视图.不可见);
imageButton.animate().x(ButtonInitial).y(buttonYinitial).setDuration(1000);
}
});
anim.start();
}
}
***//这是activity_main.xml***
package redblood.myself.animateparticulerviewonlayout;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewPropertyAnimator;
import android.view.animation.Interpolator;
import android.widget.ImageButton;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {
    ImageButton imageButton;
    ImageView imageView;
    // here we save initial postion of button so we can come again
    // after moving
    int buttonxIntial,buttonYinitial;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageView= (ImageView) findViewById(R.id.screenView);
    imageView.setVisibility(View.INVISIBLE);
    imageButton= (ImageButton) findViewById(R.id.imageButton);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

                buttonxIntial= (int) v.getPivotX();
                buttonYinitial= (int) v.getPivotY();
                final ViewPropertyAnimator anim=         v.animate().xBy((imageView.getWidth()/2)-20).yBy((imageView.getHeight()/2)-15).setDuration(1000);
                anim.setListener(new AnimatorListenerAdapter() {

                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        show(imageView);
                    }
                });
        }
    });

}

private void show(View view) {
    int x=view.getWidth()/2;
    int y=view.getHeight()/2;
    int rad=Math.max(view.getWidth(),view.getHeight());
    final Animator anim= ViewAnimationUtils.createCircularReveal(view,x,y,0,rad);
    anim.setDuration(1000);
    view.setVisibility(View.VISIBLE);
    anim.start();
}


//here i am override back buuton so when i back my button can go
//to its orginal position
@Override
public void onBackPressed() {

    hide(imageView);

}

private void hide(ImageView view) {
    int x=view.getWidth()/2;
    int y=view.getHeight()/2;
    int rad=Math.max(view.getWidth(),view.getHeight());
    Animator anim= ViewAnimationUtils.createCircularReveal(view,x,y,rad,0);
    anim.setDuration(1000);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
           super.onAnimationEnd(animation);
            imageView.setVisibility(View.INVISIBLE);
               imageButton.animate().x(buttonxIntial).y(buttonYinitial).setDuration(1000);
        }
    });
    anim.start();
}
}




***//This is activity_main.xml***

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"                    android:layout_width="match_parent"
android:layout_height="match_parent"      android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bg"
        android:id="@+id/imageButton"
        android:src="@drawable/ic_album_24dp"
        />
<ImageView
    android:background="#343434"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/screenView"
    />

</RelativeLayout>