66import android .graphics .Color ;
77import android .graphics .Paint ;
88import android .graphics .Path ;
9+ import android .graphics .PixelFormat ;
10+ import android .graphics .PorterDuff ;
911import android .util .AttributeSet ;
1012import android .util .SparseArray ;
1113
@@ -97,6 +99,7 @@ public class WaveLineView extends RenderView {
9799 //是否开启准备动画
98100 private boolean isOpenPrepareAnim = false ;
99101
102+ private boolean isTransparentMode = false ;
100103 public WaveLineView (Context context ) {
101104 this (context , null );
102105 }
@@ -119,22 +122,34 @@ private void initAttr(AttributeSet attrs) {
119122 fineLineWidth = (int )t .getDimension (R .styleable .WaveLineView_wlvFineLineWidth , 2 );
120123 offsetSpeed = t .getFloat (R .styleable .WaveLineView_wlvMoveSpeed , DEFAULT_OFFSET_SPEED );
121124 sensibility = t .getInt (R .styleable .WaveLineView_wlvSensibility , DEFAULT_SENSIBILITY );
125+ isTransparentMode = backGroundColor == Color .TRANSPARENT ;
122126 t .recycle ();
123127 checkVolumeValue ();
124128 checkSensibilityValue ();
129+ //将RenderView放到最顶层
130+ setZOrderOnTop (true );
131+ if (getHolder () != null ) {
132+ //使窗口支持透明度
133+ getHolder ().setFormat (PixelFormat .TRANSLUCENT );
134+ }
125135 }
126136
127137 @ Override
128138 protected void doDrawBackground (Canvas canvas ) {
129139 //绘制背景
130- canvas .drawColor (backGroundColor );
140+ if (isTransparentMode ) {
141+ //启用CLEAR模式,所绘制内容不会提交到画布上。
142+ canvas .drawColor (backGroundColor , PorterDuff .Mode .CLEAR );
143+ }else {
144+ canvas .drawColor (backGroundColor );
145+ }
131146 }
132147
133148 @ Override
134149 protected void onRender (Canvas canvas , long millisPassed ) {
135150 float offset = millisPassed / offsetSpeed ;
136151
137- if (null == samplingX ){
152+ if (null == samplingX || null == mapX || null == pathFuncs ){
138153 initDraw (canvas );
139154 }
140155
0 commit comments