ViewAnimationUtils的学习记录

    xiaoxiao2021-04-14  33

    Android转场动画ViewAnimationUtils的学习笔记。

    效果图:

    第二个界面的布局文件:

    <ImageView android:id="@+id/iv" android:background="@mipmap/girl" android:layout_width="match_parent" android:layout_height="match_parent"/>

    使用ViewAnimationUtils之前需要先设置“沉浸式”

    @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus && Build.VERSION.SDK_INT >= 19) { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } }

    计算动画开始和结束的半径:

    int cx=(iv.getLeft()+iv.getRight())/2; int cy=(iv.getTop()+iv.getBottom())/2; //开始半径 float startX=0f; //结束半径 float startY = (float) Math.sqrt(cx * cx + cy * cy);

    执行动画:

    Animator animator = ViewAnimationUtils.createCircularReveal(iv, cx, cy, startX, startY); animator.setInterpolator(new AccelerateInterpolator()); animator.setDuration(400); animator.start();

    完整代码:

    final ImageView iv=(ImageView) findViewById(R.id.iv); iv.post(new Runnable() { @Override public void run() { int cx=(iv.getLeft()+iv.getRight())/2; int cy=(iv.getTop()+iv.getBottom())/2; //开始半径 float startX=0f; //结束半径 float startY = (float) Math.sqrt(cx * cx + cy * cy); Animator animator = ViewAnimationUtils.createCircularReveal(iv, cx, cy, startX, startY); animator.setInterpolator(new AccelerateInterpolator()); animator.setDuration(400); animator.start(); } });
    转载请注明原文地址: https://ju.6miu.com/read-670104.html

    最新回复(0)