Android仿通话来电界面效果
Android仿通话来电界面,供大家参考,具体内容如下
简介:开发中需要模拟来电时的通话界面,仿照来电界面实现来电时播放铃声,界面通过动画模拟来电动效。
【Android仿通话来电界面效果】效果图:
文章图片
自定义图片背景,图片由小变大的动态效果。
shap_circle.xml
布局文件activity_my_call.xml
MyCallActivity.java
public class MyCallActivity extends AppCompatActivity {ImageView iv1, iv2; private MediaPlayer mMediaPlayer; @Overrideprotected 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(); }@Overrideprotected void onPause() {super.onPause(); iv1.clearAnimation(); iv2.clearAnimation(); }@Overrideprotected 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); //缩放动画,以中心从原始放大到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); //渐变动画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); //缩放动画,以中心从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); //渐变动画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); }}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
推荐阅读
- android第三方框架(五)ButterKnife
- Android中的AES加密-下
- 带有Hilt的Android上的依赖注入
- android|android studio中ndk的使用
- Android事件传递源码分析
- RxJava|RxJava 在Android项目中的使用(一)
- Android7.0|Android7.0 第三方应用无法访问私有库
- 深入理解|深入理解 Android 9.0 Crash 机制(二)
- android防止连续点击的简单实现(kotlin)
- Android|Android install 多个设备时指定设备