Android 如何使用圆形显示动画更改按钮背景?

Android 如何使用圆形显示动画更改按钮背景?,android,animation,vector,android-animation,drawable,Android,Animation,Vector,Android Animation,Drawable,我刚刚为自己探索了向量,现在希望为按钮创建以下示例动画: 圆圈和蜱虫有一个轻微的放松,蜱虫在移动到最终位置之前变得更大 我在after effects中制作了这个动画,并找到了一个非常酷的工具,可以将此权限作为json文件导出到Android中: 但是这种方法会在我的应用程序中使用另一个插件,这些动画会比矢量可绘制的动画占用更多的空间,并且矢量比我认为的导入动画更具可缩放性 那么,有没有可能用矢量绘图来制作这样的动画呢?还是我对乐蒂插件还满意 编辑 因此,我提出了以下不太令人满意的解决方案:

我刚刚为自己探索了向量,现在希望为按钮创建以下示例动画:

圆圈和蜱虫有一个轻微的放松,蜱虫在移动到最终位置之前变得更大

我在after effects中制作了这个动画,并找到了一个非常酷的工具,可以将此权限作为json文件导出到Android中:

但是这种方法会在我的应用程序中使用另一个插件,这些动画会比矢量可绘制的动画占用更多的空间,并且矢量比我认为的导入动画更具可缩放性

那么,有没有可能用矢量绘图来制作这样的动画呢?还是我对乐蒂插件还满意

编辑

因此,我提出了以下不太令人满意的解决方案:

我用PNG制作了它,但它也适用于向量,但它真的是修补过了。守则:

爪哇:

XML:


有没有更好的解决办法?或者我可以用这个吗

public class TestActivity extends AppCompatActivity {

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

//The light-green transition between the 2 buttons:

    final Button imageView = (Button) findViewById(R.id.imageView); 
//ImageView won't get over a button in the XML


//The green button with tick:

    final Button button_ok = (Button) findViewById(R.id.button_ok);

//The yellow button:

    final Button button = (Button) findViewById(R.id.button);


    button.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            show(button_ok, imageView,button, motionEvent);
            return false;
        }
    });
    button_ok.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            show(button, null,button_ok, motionEvent);
            return false;
        }
    });


}

// To reveal a previously invisible view using this effect:
private void show(final View view, final View circle, final View tobegone, final MotionEvent me) {

    final Button imageView = (Button) findViewById(R.id.imageView);

    if (circle==null){


        // get the final radius for the clipping circle
        int finalRadius = Math.max(view.getWidth(), view.getHeight());

        // create the animator for this view (the start radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(view, (int) me.getX(), (int) me.getY(),
                0, finalRadius);
        anim.setDuration(100);
        anim.setInterpolator(new FastOutSlowInInterpolator());

        // make the view invisible when the animation is done
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                imageView.setVisibility(View.INVISIBLE);
                tobegone.setVisibility(View.INVISIBLE);
            }
        });

        // make the view visible and start the animation
        view.setVisibility(View.VISIBLE);
        anim.start();

        return;
    }


    // get the final radius for the clipping circle
    int finalRadiusCircle = Math.max(view.getWidth(), view.getHeight());

    // create the animator for this view (the start radius is zero)
    Animator animcircle = ViewAnimationUtils.createCircularReveal(circle, (int) me.getX(), (int) me.getY(),
            0, finalRadiusCircle);
    animcircle.setDuration(500);
    animcircle.setInterpolator(new FastOutSlowInInterpolator());

    // make the view visible and start the animation
    circle.setVisibility(View.VISIBLE);
    animcircle.start();



    // get the final radius for the clipping circle
    int finalRadius = Math.max(view.getWidth(), view.getHeight());

    // create the animator for this view (the start radius is zero)
    Animator anim = ViewAnimationUtils.createCircularReveal(view, (int) me.getX(), (int) me.getY(),
            0, finalRadius);
    anim.setDuration(1000);
    anim.setInterpolator(new FastOutSlowInInterpolator());

    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            tobegone.setVisibility(View.INVISIBLE);
        }
    });

    // make the view visible and start the animation
    view.setVisibility(View.VISIBLE);
    anim.start();



    Handler handler = new Handler();

    final Runnable r = new Runnable() {
        public void run() {


        }
    };

    handler.postDelayed(r, 200);

}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:background="#39000000"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">

<Button
    android:id="@+id/button"
    android:layout_width="300dp"
    android:layout_height="75dp"
    android:background="@mipmap/add_button_v2"
    tools:layout_editor_absoluteX="42dp"
    tools:layout_editor_absoluteY="420dp" />

<Button
    android:id="@+id/imageView"
    android:layout_width="300dp"
    android:layout_height="75dp"
    android:background="@mipmap/add_button_v2"
    android:backgroundTint="#974caf50"
    android:backgroundTintMode="src_over"
    tools:layout_editor_absoluteX="42dp"
    tools:layout_editor_absoluteY="420dp" />

<Button
    android:id="@+id/button_ok"
    android:layout_width="300dp"
    android:layout_height="75dp"
    android:background="@mipmap/ok_button"
    tools:layout_editor_absoluteX="42dp"
    tools:layout_editor_absoluteY="420dp" />