国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android仿微信雷達(dá)掃描效果的實(shí)現(xiàn)方法

2019-10-23 18:27:23
字體:
供稿:網(wǎng)友

本文主要給大家介紹的是關(guān)于Android實(shí)現(xiàn)微信android/55801.html">android/209849.html">雷達(dá)掃描效果的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面來看看詳細(xì)的介紹:

廢話不多說 先上圖(用AS錄制的 轉(zhuǎn)換工具不是很好 所以看得效果不是很好)

效果圖

android,雷達(dá)掃描效果,仿微信掃描,雷達(dá)掃描動畫

示例代碼

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);   //根據(jù)屏幕長、寬計(jì)算掃描圓的直徑   int diameter = (int) Math.sqrt(Math.pow(height, 2) + Math.pow(width, 2));   //修改光束的大小,使光束可以掃描到整個屏幕   FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(diameter, diameter);   ivLightbeam.setLayoutParams(layoutParams);   //將掃描光束的中心移至屏幕內(nèi)容中心   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);//循環(huán)掃描  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>

繪制雷達(dá)波紋

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

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網(wǎng)的支持。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 惠水县| 江达县| 昌吉市| 河东区| 仁寿县| 年辖:市辖区| 巴彦县| 淮南市| 万安县| 宝坻区| 凤翔县| 原阳县| 安泽县| 五莲县| 和政县| 开平市| 岚皋县| 永登县| 海口市| 博野县| 女性| 墨脱县| 沽源县| 新干县| 临武县| 汉中市| 新乐市| 十堰市| 新绛县| 陕西省| 长兴县| 祁连县| 泗水县| 恩平市| 南召县| 长乐市| 紫金县| 高淳县| 怀远县| 建瓯市| 景宁|