Android仿通話來電界面效果
Android仿通話來電界面,供大家參考,具體內(nèi)容如下
簡介:開發(fā)中需要模擬來電時(shí)的通話界面,仿照來電界面實(shí)現(xiàn)來電時(shí)播放鈴聲,界面通過動(dòng)畫模擬來電動(dòng)效。
效果圖:
自定義圖片背景,圖片由小變大的動(dòng)態(tài)效果。
shap_circle.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="65dp"/> <solid android:color="#31DE87"/> </shape>
布局文件activity_my_call.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:keepScreenOn="true" tools:context=".MyCall.MyCallActivity"> <ImageView android:id="@+id/iv_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@mipmap/img1"/> <ImageView android:id="@+id/iv_head" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:src="@mipmap/header" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> <TextView android:id="@+id/tv_phone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="+86-123-4567 8910" android:textSize="24sp" android:textStyle="bold" android:textColor="#fff" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/iv_head"/> <TextView android:id="@+id/tv_from" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:textColor="#fff" android:textSize="20sp" android:text="深圳市 中國移動(dòng)來電" app:layout_constraintTop_toBottomOf="@id/tv_phone" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"/> <ImageView android:id="@+id/iv_hang_up" android:layout_width="64dp" android:layout_height="64dp" android:src="@mipmap/hang_up" android:layout_marginBottom="60dp" app:layout_constraintBottom_toTopOf="@id/iv_wave1" app:layout_constraintStart_toStartOf="@id/iv_wave1" app:layout_constraintEnd_toEndOf="@id/iv_wave1" /> <ImageView android:id="@+id/iv_wave1" android:layout_width="60dp" android:layout_height="60dp" android:layout_marginBottom="200dp" android:background="@drawable/shape_circle" app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"/> <ImageView android:id="@+id/iv_wave2" android:layout_width="60dp" android:layout_height="60dp" android:background="@drawable/shape_circle" app:layout_constraintTop_toTopOf="@id/iv_wave1" app:layout_constraintBottom_toBottomOf="@id/iv_wave1" app:layout_constraintStart_toStartOf="@id/iv_wave1" app:layout_constraintEnd_toEndOf="@id/iv_wave1"/> <ImageView android:id="@+id/iv_call" android:layout_width="48dp" android:layout_height="48dp" android:src="@mipmap/call_in" app:layout_constraintTop_toTopOf="@id/iv_wave1" app:layout_constraintBottom_toBottomOf="@id/iv_wave1" app:layout_constraintStart_toStartOf="@id/iv_wave1" app:layout_constraintEnd_toEndOf="@id/iv_wave1"/> <ImageView android:id="@+id/iv_answer" android:layout_width="64dp" android:layout_height="64dp" android:src="@mipmap/answer" android:layout_marginTop="60dp" app:layout_constraintStart_toStartOf="@id/iv_wave1" app:layout_constraintEnd_toEndOf="@id/iv_wave1" app:layout_constraintTop_toBottomOf="@id/iv_wave1"/> </androidx.constraintlayout.widget.ConstraintLayout>
MyCallActivity.java
public class MyCallActivity extends AppCompatActivity { ImageView iv1, iv2; private MediaPlayer mMediaPlayer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_call); ImageView ivBg = findViewById(R.id.iv_bg); Glide.with(this) .load(R.mipmap.img2) .apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 6))) .into(ivBg); iv1 = findViewById(R.id.iv_wave1); iv2 = findViewById(R.id.iv_wave2); mMediaPlayer = MediaPlayer.create(this, RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE)); mMediaPlayer.setLooping(true); playRingTone(); setAnim1(); setAnim2(); } @Override protected void onPause() { super.onPause(); iv1.clearAnimation(); iv2.clearAnimation(); } @Override protected void onDestroy() { super.onDestroy(); stopRingTone(); } public void playRingTone(){ if (mMediaPlayer.isPlaying()) { return; } mMediaPlayer.start(); } public void stopRingTone() { if (mMediaPlayer.isPlaying()) { mMediaPlayer.stop(); mMediaPlayer.release(); } } private void setAnim1() { AnimationSet as = new AnimationSet(true); //縮放動(dòng)畫,以中心從原始放大到1.4倍 ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.4f, 1.0f, 1.4f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); //漸變動(dòng)畫 AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f); scaleAnimation.setDuration(800); scaleAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatCount(Animation.INFINITE); as.setDuration(800); as.addAnimation(scaleAnimation); as.addAnimation(alphaAnimation); iv1.startAnimation(as); } private void setAnim2() { AnimationSet as = new AnimationSet(true); //縮放動(dòng)畫,以中心從1.4倍放大到1.8倍 ScaleAnimation scaleAnimation = new ScaleAnimation(1.4f, 1.8f, 1.4f, 1.8f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); //漸變動(dòng)畫 AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 0.1f); scaleAnimation.setDuration(800); scaleAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatCount(Animation.INFINITE); as.setDuration(800); as.addAnimation(scaleAnimation); as.addAnimation(alphaAnimation); iv2.startAnimation(as); } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決EditText、ListView以及GridView同時(shí)使用,輸入法自動(dòng)跳出來的方法
本篇文章是對在Android中EditText、ListView以及GridView同時(shí)使用,輸入法自動(dòng)跳出來的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Android使用注解代替枚舉節(jié)省系統(tǒng)內(nèi)存開銷的方法
在本篇文章里小編給大家整理的是關(guān)于Android使用注解代替枚舉節(jié)省系統(tǒng)內(nèi)存開銷的方法和實(shí)例,需要的朋友們參考下。2020-01-01Android audio音頻流數(shù)據(jù)異常問題解決分析
這篇文章主要為大家介紹了Android audio音頻流數(shù)據(jù)異常問題解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Flutter runApp GestureBinding使用介紹
這篇文章主要為大家介紹了Flutter runApp GestureBinding使用介紹,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12Android切換至SurfaceView時(shí)閃屏(黑屏閃一下)以及黑屏移動(dòng)問題的解決方法
本文主要介紹了Android切換至SurfaceView時(shí)閃屏(黑屏閃一下)以及黑屏移動(dòng)問題的解決方法。具有一定的參考作用,下面跟著小編一起來看下吧2017-01-01Android實(shí)現(xiàn)拍照、錄像、錄音代碼范例
這篇文章主要介紹了Android實(shí)現(xiàn)拍照、錄像、錄音代碼的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-10-10Android 利用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)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2015-11-11Ubuntu16.04 LTS 下安裝 Android Studio 2.2.2 的詳細(xì)步驟
這篇文章主要介紹了Ubuntu16.04 LTS 下安裝 Android Studio 2.2.2 的詳細(xì)步驟,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11