android 仿微信扫描,Android仿微信雷达扫描效果的实现方法

本文主要给大家介绍的是关于Android实现微信雷达扫描效果的相关内容,分享出来供大家参考学习,下面来看看详细的介绍:

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

效果图

6f8f335993c3524666fbd51780606253.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 布局文件

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">

android:id="@+id/ivWave"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_margin="5dp"

android:src="@drawable/wave" />

android:id="@+id/ivLightbeam"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:src="@drawable/light_beam" />

绘制扫描光束

xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="oval">

android:width="500dp"

android:height="500dp" />

android:endColor="#AAAAAAAA"

android:startColor="#00000000"

android:type="sweep"

/>

绘制雷达波纹

android:width="600dp"

android:height="600dp" />

android:color="#10B8B8B8"

android:dashWidth="1dp" />

android:bottom="100dp"

android:left="100dp"

android:right="100dp"

android:top="100dp">

android:color="#1CB8B8B8"

android:dashWidth="1dp" />

android:bottom="200dp"

android:left="200dp"

android:right="200dp"

android:top="200dp">

android:color="#2CB8B8B8"

android:dashWidth="1dp" />

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值