这篇文章将为大家详细讲解有关Android怎么实现微信聊天语言点击喇叭动画效果,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
目前创新互联建站已为超过千家的企业提供了网站建设、域名、虚拟空间、网站托管、服务器托管、企业网站设计、永顺网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。微信聊天界面点击语音时,喇叭的动画效果,下面上代码,该类是控制背景变化的工具类,不涉及语音录制和播放。
图片资源:
package xxx; import android.os.Handler; import android.widget.ImageView; import xxx.R; import java.util.Timer; import java.util.TimerTask; public class VoicePlayingBgUtil { private Handler handler; private ImageView imageView; private ImageView lastImageView; private Timer timer = new Timer(); private TimerTask timerTask; private int i; private int modelType = 1;//类型 private int[] leftVoiceBg = new int[] { R.drawable.gray1, R.drawable.gray2, R.drawable.gray3 }; private int[] rightVoiceBg = new int[] { R.drawable.green1, R.drawable.green2, R.drawable.green3 }; private int[] collectVoiceBg = new int[] { R.drawable.collect_voice_1, R.drawable.collect_voice_2, R.drawable.collect_voice_3 }; public VoicePlayingBgUtil(Handler handler) { super(); this.handler = handler; } public void voicePlay() { if (imageView == null) { return; } i = 0; timerTask = new TimerTask() { @Override public void run() { if (imageView != null) { if (modelType == 1) { changeBg(leftVoiceBg[i % 3], false); }else if(modelType==2){ changeBg(rightVoiceBg[i % 3], false); }else if(modelType==3){ changeBg(collectVoiceBg[i % 3], false); } } else { return; } i++; } }; timer.schedule(timerTask, 0, 500); } public void stopPlay() { lastImageView = imageView; if (lastImageView != null) { switch (modelType) { case 1: changeBg(R.drawable.gray3, true); break; case 2: changeBg(R.drawable.green3, true); break; case 3: changeBg(R.drawable.collect_voice_3, true); default: changeBg(R.drawable.gray3, true); break; } if (timerTask != null) { timerTask.cancel(); } } } private void changeBg(final int id, final boolean isStop) { handler.post(new Runnable() { @Override public void run() { if (isStop) { lastImageView.setImageResource(id); } else { imageView.setImageResource(id); } } }); } public void setImageView(ImageView imageView) { this.imageView = imageView; } public void setModelType(int modelType) { this.modelType = modelType; } }
调用方法
playBgUtil = new VoicePlayingBgUtil(handler); playBgUtil.stopPlay(); playBgUtil.voicePlay();
关于“Android怎么实现微信聊天语言点击喇叭动画效果”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。