Skip to content

Commit e96d29f

Browse files
committed
fix #3
1 parent 6a06f2b commit e96d29f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:id="@+id/waveLineView"
1414
android:layout_width="match_parent"
1515
android:layout_height="120dp"
16+
app:wlvBackgroundColor="@android:color/transparent"
1617
/>
1718

1819

library/src/main/java/jaygoo/widget/wlv/WaveLineView.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.graphics.Color;
77
import android.graphics.Paint;
88
import android.graphics.Path;
9+
import android.graphics.PixelFormat;
10+
import android.graphics.PorterDuff;
911
import android.util.AttributeSet;
1012
import 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

Comments
 (0)