not centered text in button
This commit is contained in:
parent
05e5ffba3d
commit
2754e11c1c
@ -11,6 +11,7 @@
|
|||||||
a:text="@string/c_history_button"
|
a:text="@string/c_history_button"
|
||||||
calc:textUp="@string/c_undo"
|
calc:textUp="@string/c_undo"
|
||||||
calc:textDown="@string/c_redo"
|
calc:textDown="@string/c_redo"
|
||||||
|
calc:hTextPosition="0.33"
|
||||||
style="?controlButtonStyle"
|
style="?controlButtonStyle"
|
||||||
a:textStyle="bold"
|
a:textStyle="bold"
|
||||||
a:onClick="historyButtonClickHandler"/>
|
a:onClick="historyButtonClickHandler"/>
|
@ -4,6 +4,7 @@
|
|||||||
<attr name="textUp" format="string"/>
|
<attr name="textUp" format="string"/>
|
||||||
<attr name="textDown" format="string"/>
|
<attr name="textDown" format="string"/>
|
||||||
<attr name="directionTextScale" format="float"/>
|
<attr name="directionTextScale" format="float"/>
|
||||||
|
<attr name="hTextPosition" format="float"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="NumberRangeSeekBar">
|
<declare-styleable name="NumberRangeSeekBar">
|
||||||
|
@ -59,6 +59,9 @@ public class ColorButton extends Button {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final OnClickListenerVibrator onClickListener;
|
private final OnClickListenerVibrator onClickListener;
|
||||||
|
|
||||||
|
private static final float H_TEXT_POSITION_DEFAULT_VALUE = 0.5f;
|
||||||
|
private float hTextPosition = H_TEXT_POSITION_DEFAULT_VALUE;
|
||||||
|
|
||||||
public ColorButton(Context context, AttributeSet attrs) {
|
public ColorButton(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, true);
|
this(context, attrs, true);
|
||||||
}
|
}
|
||||||
@ -106,7 +109,7 @@ public class ColorButton extends Button {
|
|||||||
private Point2d getTextPosition(@NotNull Paint paint, @NotNull CharSequence text) {
|
private Point2d getTextPosition(@NotNull Paint paint, @NotNull CharSequence text) {
|
||||||
final Point2d result = new Point2d();
|
final Point2d result = new Point2d();
|
||||||
|
|
||||||
result.setX((getWidth() - paint.measureText(text.toString())) / 2);
|
result.setX(hTextPosition * getWidth() - 0.5f * paint.measureText(text.toString()));
|
||||||
|
|
||||||
float height = getHeight() - paint.ascent() - paint.descent();
|
float height = getHeight() - paint.ascent() - paint.descent();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user