Relayout NoRelayoutTextView if text gets longer (#6587)
This commit is contained in:
parent
ca9358234f
commit
49ac7a83b8
@ -1,6 +1,5 @@
|
|||||||
package de.danoeh.antennapod.view;
|
package de.danoeh.antennapod.view;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -8,6 +7,9 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.appcompat.widget.AppCompatTextView;
|
import androidx.appcompat.widget.AppCompatTextView;
|
||||||
|
|
||||||
public class NoRelayoutTextView extends AppCompatTextView {
|
public class NoRelayoutTextView extends AppCompatTextView {
|
||||||
|
private boolean requestLayoutEnabled = false;
|
||||||
|
private float maxTextLength = 0;
|
||||||
|
|
||||||
public NoRelayoutTextView(@NonNull Context context) {
|
public NoRelayoutTextView(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@ -20,9 +22,21 @@ public class NoRelayoutTextView extends AppCompatTextView {
|
|||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingSuperCall")
|
|
||||||
@Override
|
@Override
|
||||||
public void requestLayout() {
|
public void requestLayout() {
|
||||||
// Deliberate no-op
|
if (requestLayoutEnabled) {
|
||||||
|
super.requestLayout();
|
||||||
|
}
|
||||||
|
requestLayoutEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setText(CharSequence text, BufferType type) {
|
||||||
|
float textLength = getPaint().measureText(text.toString());
|
||||||
|
if (textLength > maxTextLength) {
|
||||||
|
maxTextLength = textLength;
|
||||||
|
requestLayoutEnabled = true;
|
||||||
|
}
|
||||||
|
super.setText(text, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user