我发现了很多关于如何子类化文本视图的信息。垂直显示文本&。android垂直textview与图像旁边
Iam试图在文本旁边显示一颗星,并发现问题。也许你对此有一些想法。
子类:
public class VerticalTextView extends TextView
{
final boolean topDown;
public VerticalTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
final int gravity = getGravity();
if (Gravity.isVertical(gravity)
&& (gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM)
{
setGravity((gravity & Gravity.HORIZONTAL_GRAVITY_MASK)
| Gravity.TOP);
topDown = false;
}
else
{
topDown = true;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
@Override
protected void onDraw(Canvas canvas)
{
TextPaint textPaint = getPaint();
textPaint.setColor(getCurrentTextColor());
textPaint.drawableState = getDrawableState();
canvas.save();
if (topDown)
{
canvas.translate(getWidth(), 0);
canvas.rotate(90);
}
else
{
canvas.translate(0, getHeight());
canvas.rotate(-90);
}
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
getLayout().draw(canvas);
canvas.restore();
}
}
和荫设置明星从我的片段验证码:
ItemTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.btn_star_big_on, 0);
没有明星是displayed.only空白。 和想法?
该子类用于列表视图。 在一个特定的条件下,我希望在它旁边有一个星标,因此**我想我必须通过代码来完成它。
只需使用复合可绘制的那 – 2012-07-11 14:48:48
你能否详细说明一下? – Ray 2012-07-11 14:51:11
放弃了这个想法。无法让它工作。 – Ray 2012-07-15 16:20:35