Always readjust image views if heigh/width has changed
This commit is contained in:
parent
bc8886fe65
commit
964288b61d
@ -82,9 +82,13 @@ public class Adjuster {
|
|||||||
private static abstract class BaseViewAdjuster<V extends View> implements ViewTreeObserver.OnPreDrawListener {
|
private static abstract class BaseViewAdjuster<V extends View> implements ViewTreeObserver.OnPreDrawListener {
|
||||||
@NonNull
|
@NonNull
|
||||||
protected final V view;
|
protected final V view;
|
||||||
|
protected final boolean oneShot;
|
||||||
|
private int usedWidth;
|
||||||
|
private int usedHeight;
|
||||||
|
|
||||||
protected BaseViewAdjuster(@NonNull V view) {
|
protected BaseViewAdjuster(@NonNull V view, boolean oneShot) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
this.oneShot = oneShot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,9 +98,16 @@ public class Adjuster {
|
|||||||
if (!ViewCompat.isLaidOut(view) || height <= 0 || width <= 0) {
|
if (!ViewCompat.isLaidOut(view) || height <= 0 || width <= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
if (usedWidth == width && usedHeight == height) {
|
||||||
if (treeObserver != null) {
|
return true;
|
||||||
treeObserver.removeOnPreDrawListener(this);
|
}
|
||||||
|
usedWidth = width;
|
||||||
|
usedHeight = height;
|
||||||
|
if (oneShot) {
|
||||||
|
final ViewTreeObserver treeObserver = getTreeObserver(view);
|
||||||
|
if (treeObserver != null) {
|
||||||
|
treeObserver.removeOnPreDrawListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return adjust(width, height);
|
return adjust(width, height);
|
||||||
}
|
}
|
||||||
@ -110,7 +121,7 @@ public class Adjuster {
|
|||||||
private final Helper<V> helper;
|
private final Helper<V> helper;
|
||||||
|
|
||||||
public TextViewAdjuster(@NonNull V view, @NonNull Helper<V> helper, float percentage, float minTextSizePxs) {
|
public TextViewAdjuster(@NonNull V view, @NonNull Helper<V> helper, float percentage, float minTextSizePxs) {
|
||||||
super(view);
|
super(view, true);
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
this.percentage = percentage;
|
this.percentage = percentage;
|
||||||
this.minTextSizePxs = minTextSizePxs;
|
this.minTextSizePxs = minTextSizePxs;
|
||||||
@ -133,7 +144,7 @@ public class Adjuster {
|
|||||||
private final int maxWidth;
|
private final int maxWidth;
|
||||||
|
|
||||||
public MaxWidthAdjuster(@NonNull View view, int maxWidth) {
|
public MaxWidthAdjuster(@NonNull View view, int maxWidth) {
|
||||||
super(view);
|
super(view, true);
|
||||||
this.maxWidth = maxWidth;
|
this.maxWidth = maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +164,7 @@ public class Adjuster {
|
|||||||
private final float percentage;
|
private final float percentage;
|
||||||
|
|
||||||
public ImageViewAdjuster(@NonNull ImageView view, float percentage) {
|
public ImageViewAdjuster(@NonNull ImageView view, float percentage) {
|
||||||
super(view);
|
super(view, false);
|
||||||
this.percentage = percentage;
|
this.percentage = percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user