1.Android 58同城数据加载动画(组合控件实战)

 

 

demo下载地址:

demo地址:https://github.com/pengcaihua123456/shennandadao

 

功能分析:

包含:移动,缩放,旋转!!!

组合自定义View

动画直接写在控件里面进行控制。

差值器的使用

动画监听的使用

总结:该动画可用组合控件 + AnimatorSet 实现

 

动画不生效的原因:

1.属性值写错了,就会有问题translationY

 

分析:

下落的时候,阴影变小。

上抛的时候阴影变大(监听动画执行完毕)

下落的时候速度越来越快(差值器)

上抛的时候速度比较慢(差值器)

上抛的时候进行旋转

 

动画监听:有几种方式

animatorSet.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);

        startUpAnimaor();//可以把这3个动画写在一起
        //进行旋转
        startRoration();
    }
});

 

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_gravity="center"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/shapeLoadingView"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_centerHorizontal="true"
        android:src="@mipmap/ic_launcher"
        android:layout_marginTop="4dp" />

    <View
        android:id="@+id/indication"
        android:layout_width="23dp"
        android:layout_height="3dp"
        android:layout_centerHorizontal="true"
        android:background="@color/black"
        android:layout_marginTop="82dp"
         />

    <TextView
        android:id="@+id/promptTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/indication"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp"
        android:text="玩命加载中..."
        android:textColor="#757575"
        android:textSize="14sp" />
</LinearLayout>

 

/**
 * Description: 类作用描述
 *
 * @Author: 
 * Date: 2021/5/7 18:02
 **/
public class LoadingView extends LinearLayout {
    public LoadingView(Context context) {
        this(context, null);
    }

    public LoadingView(Context context, @Nullable AttributeSet attrs) {
        this(context, null, 0);
        initLayout();
    }

    public LoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;

    }


    Context mContext;
    ImageView imageView;
    View view_shadow;

    private void initLayout() {
        View view = View.inflate(mContext, R.layout.item, null);
        imageView = view.findViewById(R.id.shapeLoadingView);
        view_shadow = view.findViewById(R.id.indication);
        addView(view);

        startFallAnimator();
    }

    private void startFallAnimator() {

        Log.d("LoadingView", "startFallAnimator");
        ObjectAnimator fallobjectAnimator = ObjectAnimator.ofFloat(imageView, "translationY", 0, 200f);
        fallobjectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
        ObjectAnimator scallObjectAnimator = ObjectAnimator.ofFloat(view_shadow, "scaleX", 1f, 0.2f);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(fallobjectAnimator, scallObjectAnimator);
        animatorSet.setDuration(3000);
        animatorSet.start();

        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);

                startUpAnimaor();//可以把这3个动画写在一起
                //进行旋转
                startRoration();
            }
        });
    }

    private void startUpAnimaor() {

        Log.d("LoadingView", "startUpAnimaor");
        ObjectAnimator fallobjectAnimator = ObjectAnimator.ofFloat(imageView, "translationY", 200, 0f);
        fallobjectAnimator.setInterpolator(new DecelerateInterpolator());
        ObjectAnimator scallObjectAnimator = ObjectAnimator.ofFloat(view_shadow, "scaleX", 0.2f, 1f);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(fallobjectAnimator, scallObjectAnimator);
        animatorSet.setDuration(2000);
        animatorSet.start();
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);

                startFallAnimator();

            }
        });

    }

    private void startRoration() {

        ObjectAnimator rorateObjectAnimator = ObjectAnimator.ofFloat(imageView, "rotation", 0, 180f);
        rorateObjectAnimator.setDuration(3000);
        rorateObjectAnimator.start();
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值