Skip to content

Commit fb1ec2f

Browse files
committed
add apk
1 parent 74cec06 commit fb1ec2f

File tree

7 files changed

+185
-24
lines changed

7 files changed

+185
-24
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*.iml
22
.gradle
3-
/local.properties
3+
/local.propertie
44
/.idea/caches
55
/.idea/libraries
66
/.idea/modules.xml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
dependencies {
2727
//需要是Androidx
28-
implementation
28+
implementation 'com.github.FlodCoding:DrawableTextView:1.0.0'
2929

3030
}
3131

app/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/build
1+
1.39 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}]

app/build/outputs/logs/manifest-merger-debug-report.txt

Lines changed: 157 additions & 0 deletions
Large diffs are not rendered by default.

drawabletextview/src/main/java/com/flod/view/DrawableTextView.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,27 @@ public void setText(CharSequence text, BufferType type) {
264264

265265
/**
266266
* 设置Drawable,并设置宽高
267+
* 默认大小为Drawable的{@link Drawable#getBounds()} ,
268+
* 如果Bounds宽高为0则,取Drawable的内部固定尺寸{@link Drawable#getIntrinsicHeight()}
267269
*
268270
* @param position {@link POSITION}
269271
* @param drawable Drawable
270-
* @param width DX
271-
* @param height DX
272+
* @param width Px
273+
* @param height Px
272274
*/
273275
public void setDrawable(@POSITION int position, @Nullable Drawable drawable, @Px int width, @Px int height) {
274276
mDrawables[position] = drawable;
275277
if (drawable != null) {
276278
Rect bounds = new Rect();
277279
if (width == -1 && height == -1) {
278-
bounds.right = drawable.getIntrinsicWidth();
279-
bounds.bottom = drawable.getIntrinsicHeight();
280+
if (drawable.getBounds().width() > 0 && drawable.getBounds().height() > 0) {
281+
//如果Bounds宽高大于0,则保持默认
282+
final Rect origin = drawable.getBounds();
283+
bounds.set(origin.left, origin.top, origin.right, origin.bottom);
284+
} else {
285+
//否则取Drawable的内部大小
286+
bounds.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
287+
}
280288
} else {
281289
bounds.right = width;
282290
bounds.bottom = height;
@@ -326,28 +334,23 @@ private void storeDrawables(@Nullable Drawable start, @Nullable Drawable top, @N
326334

327335
}
328336

329-
private void clearDrawableBounds() {
330-
for (Drawable drawable : mDrawables) {
331-
if (drawable != null) {
332-
final Rect bounds = drawable.getBounds();
333-
bounds.set(0, 0, bounds.width(), bounds.height());
334-
}
335-
}
336-
}
337-
338337

339338
protected Drawable[] copyDrawables(boolean clearOffset) {
340339
Drawable[] drawables = Arrays.copyOf(getDrawables(), 4);
341340
//clear offset
342-
if (clearOffset) {
343-
for (Drawable drawable : drawables) {
344-
if (drawable != null) {
345-
Rect bounds = drawable.getBounds();
346-
bounds.offset(-bounds.left, -bounds.top);
347-
}
341+
if (clearOffset)
342+
clearOffset(drawables);
343+
344+
return drawables;
345+
}
346+
347+
private void clearOffset(Drawable... drawables) {
348+
for (Drawable drawable : drawables) {
349+
if (drawable != null) {
350+
Rect bounds = drawable.getBounds();
351+
bounds.offset(-bounds.left, -bounds.top);
348352
}
349353
}
350-
return drawables;
351354
}
352355

353356
protected int dp2px(float dpValue) {
@@ -408,7 +411,7 @@ public DrawableTextView setDrawableBottom(Drawable drawableBottom) {
408411
public DrawableTextView setEnableCenterDrawables(boolean enable) {
409412
if (enableCenterDrawables) {
410413
//清除之前的位移
411-
clearDrawableBounds();
414+
clearOffset(mDrawables);
412415
}
413416
this.enableCenterDrawables = enable;
414417
return this;

0 commit comments

Comments
 (0)