Android仿微信雷達(dá)掃描效果的實(shí)現(xiàn)方法
本文主要給大家介紹的是關(guān)于Android實(shí)現(xiàn)微信雷達(dá)掃描效果的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面來看看詳細(xì)的介紹:
廢話不多說 先上圖(用AS錄制的 轉(zhuǎn)換工具不是很好 所以看得效果不是很好)
效果圖

示例代碼
Activity 代碼
public class ShapeDrawableActivity extends AppCompatActivity {
private ImageView ivLightbeam;
private ObjectAnimator radarScanAnim; // 掃描動(dòng)畫
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)); //修改光束的大小,使光束可以掃描到整個(gè)屏幕
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í)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- Android Shader應(yīng)用開發(fā)之雷達(dá)掃描效果
- Android仿微信、QQ附近好友雷達(dá)掃描效果
- Android雷達(dá)掃描動(dòng)態(tài)界面制作
- Android自定義ViewGroup實(shí)現(xiàn)絢麗的仿支付寶咻一咻雷達(dá)脈沖效果
- Android仿支付寶上芝麻信用分雷達(dá)圖
- Android動(dòng)畫之雷達(dá)掃描效果
- Android仿微信雷達(dá)輻射搜索好友(邏輯清晰實(shí)現(xiàn)簡單)
- Android編程簡單實(shí)現(xiàn)雷達(dá)掃描效果
- 基于Android自定義控件實(shí)現(xiàn)雷達(dá)效果
相關(guān)文章
Android利用Flutter?path繪制粽子的示例代碼
端午將至,作為中華民族的非常重要的傳統(tǒng)節(jié)日,粽子那是必不可少的。今天跟隨本篇文章用Flutter?path畫一個(gè)會科普節(jié)日的的粽子吧2022-05-05
Android 8.0如何完美適配全局dialog懸浮窗彈出
這篇文章主要給大家介紹了關(guān)于Android 8.0如何完美適配全局dialog懸浮窗彈出的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起看看吧2018-07-07
Androd自定義對話框Dialog視圖及參數(shù)傳遞的實(shí)現(xiàn)方法
這篇文章主要介紹了Androd自定義對話框Dialog視圖及參數(shù)傳遞的實(shí)現(xiàn)方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01
Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實(shí)例
這篇文章主要介紹了Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實(shí)現(xiàn)方法,結(jié)合完整實(shí)例形式較為詳細(xì)的分析了Android針對登錄數(shù)據(jù)的保存及回顯操作技巧,需要的朋友可以參考下2015-12-12
Android 利用ViewPager實(shí)現(xiàn)圖片可以左右循環(huán)滑動(dòng)效果附代碼下載
本文通過一個(gè)小demo給大家展示一段代碼實(shí)現(xiàn)viewpage圖片左右循環(huán)滑動(dòng)效果,對viewgager循環(huán)滑動(dòng)相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-11-11

