Android 高仿支付宝二维码扫描动画实现 3分钟学会 人脸识别扫描线

原理:

1.把方框的位置在xml中布置好

2.把扫描线的图片也布置好

3.用平移动画,移动y轴,循环的次数反复。

 

不过我网上搜了搜很多方法都是实时绘制出来的,计算点的位置然后重绘出来。我的第一感觉是完全没必要,其实这个东西本质上就是一张贴图加一个平移动画效果,所以就自己做了一个小小例子。

  

扫描的动画效果实则就是平移动画

 

<RelativeLayout

        android:id="@+id/box_layout"

        android:layout_width="200dp"

        android:layout_height="200dp"

        android:layout_centerHorizontal="true"

        android:background="@drawable/box" >

 

        <ImageView

            android:id="@+id/scan_line"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_alignParentTop="true"

            android:layout_margin="5dp"

            android:background="@drawable/line"/>

 

    </RelativeLayout>

 

 

代码实现:

 

可以设置来回移动,移动多个参数(重要)

 

  ImageView mQrLineView = (ImageView) findViewById(R.id.scan_line);

  TranslateAnimation mAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE,0f,TranslateAnimation.RELATIVE_TO_PARENT, 0f, 

TranslateAnimation.RELATIVE_TO_PARENT, 0.9f);

  mAnimation.setDuration(1500);

  mAnimation.setRepeatCount(-1);

  mAnimation.setRepeatMode(Animation.RESTART);

  mAnimation.setInterpolator(new LinearInterpolator());

  mQrLineView.setAnimation(mAnimation);

 

 

下载地址:

https://download.csdn.net/download/u010231454/10847735

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值