From be94ef5452340f83082dd1d15eb3bddf683023ff Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Thu, 27 Oct 2011 10:28:29 +0400 Subject: [PATCH] not centered text in button --- res/layout/calc_history_button.xml | 1 + res/values/attrs.xml | 1 + .../java/org/solovyev/android/view/widgets/ColorButton.java | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/res/layout/calc_history_button.xml b/res/layout/calc_history_button.xml index f089ae2b..3b70e78e 100644 --- a/res/layout/calc_history_button.xml +++ b/res/layout/calc_history_button.xml @@ -11,6 +11,7 @@ a:text="@string/c_history_button" calc:textUp="@string/c_undo" calc:textDown="@string/c_redo" + calc:hTextPosition="0.33" style="?controlButtonStyle" a:textStyle="bold" a:onClick="historyButtonClickHandler"/> \ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 62a9826e..5cc9a057 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -4,6 +4,7 @@ + diff --git a/src/main/java/org/solovyev/android/view/widgets/ColorButton.java b/src/main/java/org/solovyev/android/view/widgets/ColorButton.java index 92b54b51..b917bb67 100644 --- a/src/main/java/org/solovyev/android/view/widgets/ColorButton.java +++ b/src/main/java/org/solovyev/android/view/widgets/ColorButton.java @@ -59,6 +59,9 @@ public class ColorButton extends Button { @NotNull 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) { this(context, attrs, true); } @@ -106,7 +109,7 @@ public class ColorButton extends Button { private Point2d getTextPosition(@NotNull Paint paint, @NotNull CharSequence text) { 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();