Android仿微信雷达扫描效果的实现方法-创新互联
本文主要给大家介绍的是关于Android实现微信雷达扫描效果的相关内容,分享出来供大家参考学习,下面来看看详细的介绍:
高州ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!废话不多说 先上图(用AS录制的 转换工具不是很好 所以看得效果不是很好)
效果图
示例代码
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(); } }
本文名称:Android仿微信雷达扫描效果的实现方法-创新互联
本文网址:http://myzitong.com/article/ccpcjj.html