如何使用Material Design Animation用另一个视图填充视图?

lop*_*ael 46 animation android material-design

我试图解决与Android Material Design集成的不同功能,但是当视图填充另一个时,我不能做这种类型的动画:

你知道怎么做或者图书馆/项目这样做的例子吗?

在此输入图像描述

N J*_*N J 46

我尝试在API 21下面实现这个

添加gradle依赖性

dependencies {
        compile 'com.github.ozodrukh:CircularReveal:1.0.6@aar'
    }
Run Code Online (Sandbox Code Playgroud)

我的活动xml是

activity_reval_anim.xml

<RelativeLayout
    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=".RevalAnimActivity">

    <ImageView
        android:id="@+id/img_top"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:background="@color/color_primary"

        android:src="@drawable/ala"/>


    <io.codetail.widget.RevealLinearLayout

        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@+id/img_top"
        android:background="@color/color_primary">
        <LinearLayout
            android:visibility="invisible"
            android:id="@+id/ll_reveal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/color_accent"
            android:orientation="horizontal"
            ></LinearLayout>

    </io.codetail.widget.RevealLinearLayout>
    <ImageButton
        android:id="@+id/img_floating_btn"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="40dp"
        android:layout_marginTop="170dp"
        android:background="@drawable/expand_btn"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的Activity是java

RevalAnimActivity.java

public class RevalAnimActivity extends ActionBarActivity {

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

        final ImageButton mFloatingButton = (ImageButton) findViewById(R.id.img_floating_btn);
        mFloatingButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                animateButton(mFloatingButton);


            }


        });

    }

    private void animateButton(final ImageButton mFloatingButton) {

        mFloatingButton.animate().translationXBy(0.5f).translationY(150).translationXBy(-0.9f)
                .translationX(-150). setDuration(300).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);

                animateReavel((int) mFloatingButton.getX(), 150,mFloatingButton);
            }
        });

    }

    private void animateReavel(int cx, int cy, final ImageButton mFloatingButton) {


        final View myView = findViewById(R.id.ll_reveal);

        // get the final radius for the clipping circle
        float finalRadius = hypo(myView.getWidth(), myView.getHeight());

        SupportAnimator animator =
                ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
        animator.addListener(new SupportAnimator.AnimatorListener() {
            @Override
            public void onAnimationStart() {
                mFloatingButton.setVisibility(View.INVISIBLE);
                myView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd() {
                Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_LONG)
                        .show();
            }

            @Override
            public void onAnimationCancel() {
            }

            @Override
            public void onAnimationRepeat() {
            }
        });
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setDuration(1000);
        animator.start();

    }

    static float hypo(int a, int b) {
        return (float) Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
    }


}
Run Code Online (Sandbox Code Playgroud)


lop*_*ael 30

这样做的解决方案是pathInterpolator,此效果的名称是Curved Motion.

材料设计中的动画依赖于时间插值曲线和空间运动模式.使用Android 5.0(API级别21)及更高版本,您可以为动画定义自定义时序曲线和曲线运动模式.

您可以在此处查看如何实现它:

http://developer.android.com/training/material/animations.html#CurvedMotion

而在GitHub上品尝这里:

在此输入图像描述

  • 但是如何在API 21下面做到这一点? (5认同)