Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit a80f869

Browse files
author
xianing
committed
add protection for layout dynamically changes
1 parent 55b936c commit a80f869

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lrcview/src/main/java/io/agora/lrcview/LrcView.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,25 +288,26 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
288288
if (changed) {
289289
int w = right - left - getPaddingStart() - getPaddingEnd();
290290
int h = bottom - top - getPaddingTop() - getPaddingBottom();
291+
if(h > 0){
292+
if (mBitmapFG == null) {
293+
createBitmapFG(w, h);
294+
} else if (mBitmapFG.getWidth() != w || mBitmapFG.getHeight() != h) {
295+
if (!mBitmapFG.isRecycled()) {
296+
mBitmapFG.recycle();
297+
}
291298

292-
if (mBitmapFG == null) {
293-
createBitmapFG(w, h);
294-
} else if (mBitmapFG.getWidth() != w || mBitmapFG.getHeight() != h) {
295-
if (!mBitmapFG.isRecycled()) {
296-
mBitmapFG.recycle();
299+
createBitmapFG(w, h);
297300
}
298301

299-
createBitmapFG(w, h);
300-
}
302+
if (mBitmapBG == null) {
303+
createBitmapBG(w, h);
304+
} else if (mBitmapBG.getWidth() != w || mBitmapBG.getHeight() != h) {
305+
if (!mBitmapBG.isRecycled()) {
306+
mBitmapBG.recycle();
307+
}
301308

302-
if (mBitmapBG == null) {
303-
createBitmapBG(w, h);
304-
} else if (mBitmapBG.getWidth() != w || mBitmapBG.getHeight() != h) {
305-
if (!mBitmapBG.isRecycled()) {
306-
mBitmapBG.recycle();
309+
createBitmapBG(w, h);
307310
}
308-
309-
createBitmapBG(w, h);
310311
}
311312

312313
mRectSrc.left = 0;
@@ -343,6 +344,9 @@ protected void onDraw(Canvas canvas) {
343344
if (!hasLrc()) {
344345
int width = getLrcWidth();
345346
int height = getLrcHeight();
347+
if(width == 0 || height ==0){
348+
return;
349+
}
346350
@SuppressLint("DrawAllocation")
347351
StaticLayout staticLayout = new StaticLayout(
348352
mDefaultLabel,
@@ -627,11 +631,11 @@ private int findShowLine(long time) {
627631
}
628632

629633
private int getLrcWidth() {
630-
return getWidth() - getPaddingStart() - getPaddingEnd();
634+
return Math.max(getWidth() - getPaddingStart() - getPaddingEnd(), 0);
631635
}
632636

633637
private int getLrcHeight() {
634-
return getHeight() - getPaddingTop() - getPaddingBottom();
638+
return Math.max((getHeight() - getPaddingTop() - getPaddingBottom()), 0);
635639
}
636640

637641
@MainThread

0 commit comments

Comments
 (0)