Android仿微信雷达扫描

废话不多说 先上图(用AS录制的 转换工具不是很好 所以看得效果不是很好)

gif5新文件.gif

Activity 代码

public class ShapeDrawableActivity extends AppCompatActivity {
    private ImageView ivLightbeam;

    private ObjectAnimator radarScanAnim;   // 扫描动画

    private int width;
    private int height;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_shape_drawable);
        ivLightbeam = (ImageView) findViewById(R.id.ivLightbeam);
    }


    @Override
    protected void onResume() {
        super.onResume();
        startScan();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (height == 0 || width == 0) {            //获取屏幕长、宽
            width = ScreenUtils.getScreenWidth(this);
            height = ScreenUtils.getScreenHeight(this);            //根据屏幕长、宽计算扫描圆的直径
            int diameter = (int) Math.sqrt(Math.pow(height, 2) + Math.pow(width, 2));            //修改光束的大小,使光束可以扫描到整个屏幕
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(diameter, diameter);
            ivLightbeam.setLayoutParams(layoutParams);            //将扫描光束的中心移至屏幕内容中心
            int offsetX = (width - diameter) / 2;
            int offsetY = (height - diameter) / 2 + ScreenUtils.getStatusHeight(this) / 2;
            ivLightbeam.setX(offsetX);
            ivLightbeam.setY(offsetY);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        stopScan();
    }    // 开始扫描

    private void startScan() {
        radarScanAnim = ObjectAnimator.ofFloat(ivLightbeam, "rotation", 0f, 360f);
        radarScanAnim.setDuration(2000);    //2秒扫描一圈
        radarScanAnim.setInterpolator(new LinearInterpolator());
        radarScanAnim.setRepeatCount(ObjectAnimator.INFINITE);//循环扫描

        ivLightbeam.setVisibility(View.VISIBLE);
        radarScanAnim.start();
    }   // 停止扫描

    private void stopScan() {
        ivLightbeam.setVisibility(View.GONE);
        radarScanAnim.end();
    }
}


Activity 布局文件

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FA000000"
    android:clipToPadding="false"
    android:fitsSystemWindows="true">

    <ImageView
        android:id="@+id/ivWave"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:src="@drawable/wave" />

    <ImageView
        android:id="@+id/ivLightbeam"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/light_beam" />

</FrameLayout>

绘制扫描光束

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <size
        android:width="500dp"
        android:height="500dp" />

    <gradient
        android:endColor="#AAAAAAAA"
        android:startColor="#00000000"
        android:type="sweep"
        />
</shape>

绘制雷达波纹

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <!--最外层圆圈-->
        <shape android:shape="oval">
            <solid android:color="#10FFFFFF" />
            <size
                android:width="600dp"
                android:height="600dp" />
            <stroke
                android:color="#10B8B8B8"
                android:dashWidth="1dp" />
        </shape>
    </item>

    <item
        android:bottom="100dp"
        android:left="100dp"
        android:right="100dp"
        android:top="100dp">
        <!--最中间层圆圈-->
        <shape android:shape="oval">
            <solid android:color="#1CFFFFFF" />
            <stroke
                android:color="#1CB8B8B8"
                android:dashWidth="1dp" />
        </shape>
    </item>

    <item
        android:bottom="200dp"
        android:left="200dp"
        android:right="200dp"
        android:top="200dp">

        <!--最中心圆圈-->
        <shape android:shape="oval">
            <solid android:color="#2CFFFFFF" />
            <stroke
                android:color="#2CB8B8B8"
                android:dashWidth="1dp" />
        </shape>
    </item>
</layer-list>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,598评论 25 708
  • 当你对各种军用雷达头大的时候,推荐你读读这一篇。 舰载雷达 |型号|应用||:-:|:-:|:-:|:-:|:-:...
    好心态阅读 7,174评论 0 7
  • 第一次参加这个活动,一时还真不知道写什么,不如说说最近求职的事情吧。 我大概属于这种人,想的太多,付出太少,看似忙...
    千叶妖精阅读 102评论 4 3
  • 文/風雨綫 时间/ 2017年3月13日 关于鄂教版里的《论语》篇,初次接触是在2015年春,七年级下册的文言文...
    風雨綫阅读 375评论 12 4
  • 一 前言 注:本文只是作为近期帮公司招募用户库的一个总结,有很多不专业不恰当的地方,请大家见谅。 微博的运营总体思...
    类猿人阅读 700评论 0 5