1

我是 android 新手,我正在尝试使用带有按钮的循环器 Reveal。所以当我点击按钮时,它会移动到中心,然后循环器显示来自中心。当我按下后退按钮时,循环器显示继续,我的按钮移动到它的中心位置。直到这里它工作正常。但是在第一次迭代后没有点击按钮循环器显示再次出现问题?

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>
4

0 回答 0