Android开发之实现苹果浏览器网页跳转动画

前言:上一章《Android开发之安卓属性动画大总结》大致介绍了安卓的属性动画以及使用时的注意点,今天我们就来一个小综合案列,实现类似于苹果浏览器的跳转页面!

----------------------分割线------------------------

来看下效果图:


----------------------分割线------------------------

分析:1.购买详情页面设置成INVISIBLE。

2.首页面同时做翻转、透明、缩放然后往上平移动画

3.详情页面开始显示出来。

4.退出的时候,动画反过来再做一遍。

----------------------分割线------------------------

代码奉上:

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {

    private LinearLayout first;
    private ImageView second;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        first = (LinearLayout) findViewById(R.id.first);
        second = (ImageView) findViewById(R.id.second);
        button = (Button) findViewById(R.id.bt);
    }

    public void startFirstAnimation(View view) {
        /**
         * 1)first_View动画:1.翻转动画;2.透明度动画;3.缩放动画
         */
        //翻转
        ObjectAnimator firstRotationAnim = ObjectAnimator.ofFloat(first, "rotationX", 0f, 25f, 0f);
        firstRotationAnim.setDuration(400);
        //透明度
        ObjectAnimator firstAlphaAnim = ObjectAnimator.ofFloat(first, "alpha", 1f, 0.5f);
        firstAlphaAnim.setDuration(300);
        //缩放
        ObjectAnimator firstScaleXAnim = ObjectAnimator.ofFloat(first, "scaleX", 1f, 0.8f);
        firstScaleXAnim.setDuration(300);
        ObjectAnimator firstScaleYAnim = ObjectAnimator.ofFloat(first, "scaleY", 1f, 0.8f);
        firstScaleYAnim.setDuration(300);
        //平移上去
        ObjectAnimator firstTranslationYAnim = ObjectAnimator.ofFloat(first, "translationY", 0f, -0.1f * first.getHeight());
        firstTranslationYAnim.setDuration(300);
        //把隐藏的给显示出来
        ObjectAnimator sencondTranslationYAnim = ObjectAnimator.ofFloat(second, "translationY", second.getHeight(), 0);
        sencondTranslationYAnim.setDuration(300);
        sencondTranslationYAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                second.setVisibility(View.VISIBLE);
                button.setClickable(false);
            }
        });
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(firstRotationAnim, firstAlphaAnim, firstScaleXAnim, firstScaleYAnim, firstTranslationYAnim, sencondTranslationYAnim);
        animatorSet.start();
    }

    public void startSecondAnimation(View view) {
        //翻转
        ObjectAnimator firstRotationAnim = ObjectAnimator.ofFloat(first, "rotationX", 0f, 25f, 0f);
        firstRotationAnim.setDuration(400);
        //透明度
        ObjectAnimator firstAlphaAnim = ObjectAnimator.ofFloat(first, "alpha", 0f, 1f);
        firstAlphaAnim.setDuration(300);
        //缩放
        ObjectAnimator firstScaleXAnim = ObjectAnimator.ofFloat(first, "scaleX", 0.8f, 1f);
        firstScaleXAnim.setDuration(300);
        ObjectAnimator firstScaleYAnim = ObjectAnimator.ofFloat(first, "scaleY", 0.8f, 1);
        firstScaleYAnim.setDuration(300);
        //把first平移下去
        ObjectAnimator firstTranslationYAnim = ObjectAnimator.ofFloat(first, "translationY", -0.1f * first.getHeight(), 0f);
        firstTranslationYAnim.setDuration(300);
        //把第二个view下移
        ObjectAnimator sencondTranslationYAnim = ObjectAnimator.ofFloat(second, "translationY", 0f, second.getHeight());
        sencondTranslationYAnim.setDuration(300);
        sencondTranslationYAnim.start();
        sencondTranslationYAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                second.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                button.setClickable(true);
            }
        });
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(firstRotationAnim, firstAlphaAnim, firstScaleXAnim, firstScaleYAnim, sencondTranslationYAnim, firstTranslationYAnim);
        animatorSet.start();
    }
}


布局代码:

<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/first"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/img01"
        android:orientation="vertical">

        <Button
            android:id="@+id/bt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#f00"
            android:onClick="startFirstAnimation"
            android:text="显示" />
    </LinearLayout>

    <ImageView
        android:id="@+id/second"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:clickable="true"
        android:onClick="startSecondAnimation"
        android:scaleType="fitEnd"
        android:src="@drawable/img02"
        android:visibility="invisible" />
</RelativeLayout>
----------------------完------------------------


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等待着冬天的风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值