not centered text in button

This commit is contained in:
serso 2011-10-27 10:28:29 +04:00
parent 183e1a9a3b
commit 0b0d07be86
3 changed files with 6 additions and 1 deletions

View File

@ -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"/>

View File

@ -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">

View File

@ -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();