Android仿通话来电界面效果

 更新时间:2021年09月24日 09:32:14   作者:tracydragonlxy  
这篇文章主要为大家详细介绍了Android仿通话来电界面效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

Android仿通话来电界面,供大家参考,具体内容如下

简介:开发中需要模拟来电时的通话界面,仿照来电界面实现来电时播放铃声,界面通过动画模拟来电动效。

效果图:

自定义图片背景,图片由小变大的动态效果。

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="深圳市 中国移动来电"
        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);
        //缩放动画,以中心从原始放大到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开发悬浮窗踩坑解决

    Android开发悬浮窗踩坑解决

    这篇文章主要为大家介绍了Android悬浮窗踩坑解决示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • Android WebView控件基本使用示例

    Android WebView控件基本使用示例

    大家好,本篇文章主要讲的是Android WebView控件基本使用示例,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下,方便下次浏览
    2022-01-01
  • android 上传aar到私有maven服务器的示例

    android 上传aar到私有maven服务器的示例

    这篇文章主要介绍了android 上传aar到私有maven服务器,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-11-11
  • Android项目开发之UI设计器

    Android项目开发之UI设计器

    这篇文章主要为大家详细介绍了Android项目开发之UI设计器,具有一定的实用性和参考价值,感兴趣的小伙伴们可以参考一下
    2016-06-06
  • Flutter异步操作实现流程详解

    Flutter异步操作实现流程详解

    在Flutter中,借助 FutureBuilder 组件和 StreamBuilder 组件,可以非常方便地完成异步操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习吧
    2022-09-09
  • Android ScrollView嵌套横向滑动控件时冲突问题

    Android ScrollView嵌套横向滑动控件时冲突问题

    本篇文章主要介绍了Android ScrollView嵌套横向滑动控件时冲突问题,具有一定的参考价值,有兴趣的可以了解一下
    2017-08-08
  • Android Studio 3.6运行模拟器时Emulator警告问题的解决方案

    Android Studio 3.6运行模拟器时Emulator警告问题的解决方案

    这篇文章主要介绍了Android Studio 3.6运行模拟器时Emulator警告问题的解决方案,本文给大家介绍的非常详细,对大家的工作或学习具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-03-03
  • flutter底部弹出BottomSheet详解

    flutter底部弹出BottomSheet详解

    这篇文章主要为大家详细介绍了flutter底部弹出BottomSheet,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • android 退出程序解决内存释放的问题

    android 退出程序解决内存释放的问题

    做Android项目的时候发现一个问题:当应用程序退出了,点击"设置"查看应用程序,界面显示着可以点击"强制关闭 由于这个问题我发现了一个更加严重的问题,那就是,在我应用程序退出之后,系统并没有释放掉我应用程序所占内存
    2012-11-11
  • 浅谈Android textview文字对齐换行的问题

    浅谈Android textview文字对齐换行的问题

    下面小编就为大家分享一篇浅谈Android textview文字对齐换行的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-01-01

最新评论