android 二维码扫描动画实现

box.9.png     

line.png      


布局:

    <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);


猜你喜欢

转载自blog.csdn.net/lindonghai/article/details/80775775
今日推荐