android 用三张图片实现七个音量等级的录音效果
2013-09-29 19:22:09 来源:WEB开发网核心提示: 很多有发送语音功能的即时通讯软件中,在录音时都有音量变化的效果,android 用三张图片实现七个音量等级的录音效果,如果QQ,微信,为了减少图片资源的容量,现在我们用三张图片来实现7个音量等级的效果,最近的易信,
很多有发送语音功能的即时通讯软件中,在录音时都有音量变化的效果,如果QQ,微信,最近的易信。。。等等,若有7个音量的效果就需要7张图片,为了减少图片资源的容量,现在我们用三张图片来实现7个音量等级的效果。
实现重点:Region.Op.DIFFERENCE
看代码:
package com.open.widget; import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.Region; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; import com.open.widget.mic.R; /** * 麦克风的录音效果 * @author yanglonghui * */ public class AudioRecordMicView extends View{ private Drawable micBgDrawable; private Drawable mic_1Drawable; private Drawable mic_2Drawable; private Rect micBgDrawableRect=new Rect(); private Rect mic_1DrawableRect=new Rect(); private Rect mic_2DrawableRect=new Rect(); private Rect spaceRect=new Rect(); private int maxLevel=7; public AudioRecordMicView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } public AudioRecordMicView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public AudioRecordMicView(Context context) { super(context); init(); } private void init() { micBgDrawable=getResources().getDrawable(R.drawable.tooltip_mic_bg); mic_1Drawable=getResources().getDrawable(R.drawable.tooltip_mic_1); mic_2Drawable=getResources().getDrawable(R.drawable.tooltip_mic_2); } /** * 设置录音的级数,从1-7 * @param level */ public void setLevel(int level) { int progress=level*mic_2DrawableRect.height()/maxLevel; setProgress(progress); } public void setMaxLevel(int maxLevel) { this.maxLevel=maxLevel; } public int getMaxLevel() { return maxLevel; } private void setProgress(int progress) { int bottom=0; if(progress>mic_2DrawableRect.height()) { bottom=0; } else { bottom=mic_2DrawableRect.height()-progress; } spaceRect.set(mic_2DrawableRect.left, mic_2DrawableRect.top, mic_2DrawableRect.right, mic_2DrawableRect.top+bottom); invalidate(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(micBgDrawable.getIntrinsicWidth(), micBgDrawable.getIntrinsicHeight()); micBgDrawableRect.set(0, 0, micBgDrawable.getIntrinsicWidth(), micBgDrawable.getIntrinsicHeight()); micBgDrawable.setBounds(micBgDrawableRect); int left=(getMeasuredWidth()-mic_1Drawable.getIntrinsicWidth())/2; int top=(getMeasuredHeight()-mic_1Drawable.getIntrinsicHeight())/2; mic_1DrawableRect.set(left, top, left+mic_1Drawable.getIntrinsicWidth(), top+mic_1Drawable.getIntrinsicHeight()); mic_1Drawable.setBounds(mic_1DrawableRect); mic_2DrawableRect.set(mic_1DrawableRect); mic_2Drawable.setBounds(mic_2DrawableRect); spaceRect.set(mic_1DrawableRect); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); micBgDrawable.draw(canvas); mic_1Drawable.draw(canvas); canvas.save(); canvas.clipRect(mic_2DrawableRect); canvas.clipRect(spaceRect,Region.Op.DIFFERENCE); mic_2Drawable.draw(canvas); canvas.restore(); } }
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接