Skip to content

Commit e80e3f4

Browse files
committed
修复未设置EndDrawable出现的无法结束loading的错误,
修复无文字时的错误
1 parent 511edd5 commit e80e3f4

File tree

4 files changed

+109
-82
lines changed

4 files changed

+109
-82
lines changed

Loadingbutton-support/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 17
99
targetSdkVersion 28
10-
versionCode 102
11-
versionName "1.0.2"
10+
versionCode 103
11+
versionName "1.0.3"
1212
}
1313

1414
buildTypes {

Loadingbutton-support/src/main/java/com/flod/loadingbutton/DrawableTextView.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import android.support.annotation.Nullable;
1111
import android.support.annotation.Px;
1212
import android.support.v7.widget.AppCompatTextView;
13+
import android.text.TextUtils;
1314
import android.util.AttributeSet;
1415
import android.view.Gravity;
1516

16-
1717
import java.lang.annotation.Retention;
1818
import java.lang.annotation.RetentionPolicy;
1919
import java.util.Arrays;
@@ -134,16 +134,19 @@ protected void onDraw(Canvas canvas) {
134134

135135
if (enableCenterDrawables && (isCenterHorizontal | isCenterVertical)) {
136136

137+
//有文字就才位移画布了
138+
boolean textNoEmpty = !TextUtils.isEmpty(getText());
137139
//画布的偏移量
138140
int transX = 0, transY = 0;
139141

142+
140143
if (mDrawables[POSITION.START] != null) {
141144
Rect bounds = mDrawablesBounds[POSITION.START];
142145
int offset = (int) calcOffset(POSITION.START);
143146
mDrawables[POSITION.START].setBounds(bounds.left + offset, bounds.top,
144147
bounds.right + offset, bounds.bottom);
145148

146-
if (isCenterHorizontal)
149+
if (isCenterHorizontal && textNoEmpty)
147150
transX -= (mDrawablesBounds[POSITION.START].width() + getCompoundDrawablePadding()) >> 1;
148151
}
149152

@@ -154,7 +157,7 @@ protected void onDraw(Canvas canvas) {
154157
mDrawables[POSITION.TOP].setBounds(bounds.left, bounds.top + offset,
155158
bounds.right, bounds.bottom + offset);
156159

157-
if (isCenterVertical)
160+
if (isCenterVertical && textNoEmpty)
158161
transY -= (mDrawablesBounds[POSITION.TOP].height() + getCompoundDrawablePadding()) >> 1;
159162
}
160163

@@ -164,7 +167,7 @@ protected void onDraw(Canvas canvas) {
164167
mDrawables[POSITION.END].setBounds(bounds.left + offset, bounds.top,
165168
bounds.right + offset, bounds.bottom);
166169

167-
if (isCenterHorizontal)
170+
if (isCenterHorizontal && textNoEmpty)
168171
transX += (mDrawablesBounds[POSITION.END].width() + getCompoundDrawablePadding()) >> 1;
169172
}
170173

@@ -174,11 +177,12 @@ protected void onDraw(Canvas canvas) {
174177
mDrawables[POSITION.BOTTOM].setBounds(bounds.left, bounds.top + offset,
175178
bounds.right, bounds.bottom + offset);
176179

177-
if (isCenterVertical)
180+
if (isCenterVertical && textNoEmpty)
178181
transY += (mDrawablesBounds[POSITION.BOTTOM].height() + getCompoundDrawablePadding()) >> 1;
179182
}
180183

181-
if (enableTextInCenter) {
184+
185+
if (enableTextInCenter && textNoEmpty) {
182186
canvas.translate(transX, transY);
183187
this.canvasTransX = transX;
184188
this.canvasTransY = transY;

0 commit comments

Comments
 (0)