我想在我的
RadioButton
上添加一个类似于CheckBoxPreference
的摘要。
我试图扩展RadioButton
并覆盖onDraw
方法,但我卡在了所有计算上,以使其布局得体。
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
int textSize = 20;
int horizontalStartPosition = getCompoundPaddingLeft() + getCompoundDrawablePadding();
int verticalStartPosition = getBaseline() + getLineHeight();
paint.setTextSize(textSize);
paint.setColor(Color.GRAY);
paint.setAntiAlias(true);
canvas.drawText(summary, horizontalStartPosition, verticalStartPosition, paint);
}
这将呈现出类似于以下内容:
这样做真的是正确的方式吗(感觉不是),还是我应该尝试完全不同的方法?