Так что у меня есть немного разочарования для меня.То, чего я хотел бы добиться, - это кнопка с двумя текстовыми изображениями в центре.Один с именем и один с числовым значением ... Как счетчик ...
Я бы хотел, чтобы это выглядело так:
Вокруг него тонкая белая рамка (учитывая, что ее цвет не совсем виден ... извините).
Мне бы хотелось, чтобы значение было увеличено науменьшение в зависимости от того, как нажата кнопка.
Теперь у меня есть следующее:
attrs.xml
<resources>
<declare-styleable name="ButtonCounter">
<attr name="backgroundColor" format="color"/>
<attr name="borderColor" format="color"/>
<attr name="borderSize" format="integer"/>
<attr name="labelNameColor" format="color"/>
<attr name="labelValueColor" format="color"/>
<attr name="labelName" format="string"></attr>
<attr name="labelValue" format="string"></attr>
</declare-styleable>
ButtonCounter.java
public class ButtonCounter extends View {
private int backgroundColor,
borderColor,
borderSize,
labelNameColor,
labelValueColor;
private String labelName,
labelValue;
private Paint paintCircle,
paintStroke;
public ButtonCounter(Context context, AttributeSet attrs) {
super(context);
paintCircle = new Paint();
paintStroke = new Paint();
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.ButtonCounter
,
0,
0
);
try {
backgroundColor = a.getInteger(R.styleable.ButtonCounter_backgroundColor, 0);
borderColor = a.getInteger(R.styleable.ButtonCounter_borderColor, 0);
borderSize = a.getInteger(R.styleable.ButtonCounter_borderSize, 0);
labelNameColor = a.getInteger(R.styleable.ButtonCounter_labelNameColor,0);
labelValueColor = a.getInteger(R.styleable.ButtonCounter_labelValueColor, 0 );
labelName = a.getString(R.styleable.ButtonCounter_labelName);
labelValue = a.getString(R.styleable.ButtonCounter_labelValue);
} finally {
a.recycle();
}
}
@Override
protected void onDraw(Canvas canvas) {
paintCircle.setColor(backgroundColor);
paintCircle.setAntiAlias(true);
paintStroke.setColor(borderColor);
paintStroke.setAntiAlias(true);
int width = this.getMeasuredWidth();
int height = this.getMeasuredHeight();
int diameter = ((height > width) ? height : width);
int radius = diameter / 2;
canvas.drawCircle(diameter / 2, diameter / 2, radius - borderSize, paintCircle);
canvas.drawCircle(diameter / 2, diameter / 2, radius, paintStroke);
}
}
Это уже не то, чего я хочу, потому что оно становится слишком большим.
Есть какие-нибудь идеи о том, как я мог бы начать пытаться это делать?
Спасибо!