Android的垂直的TextView与旁边的图像 [英] android vertical textview with image next to it

查看:132
本文介绍了Android的垂直的TextView与旁边的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

香港专业教育学院发现了很多关于如何继承一个TextView和放大器信息的;垂直显示的文字。

ive found a lot of info on how to subclass a textview & display the text vertically.

荫试图在文本旁边显示星号和IAM有问题。
也许你有这方面的一些想法。

Iam trying to display a star next to the text and iam having problems. maybe you have some ideas on this.

子类:

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

}

和荫设置从我的这个片段code星:

and Iam setting the star with this code from my fragment:

ItemTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.btn_star_big_on, 0); 

没有明星displayed.only空白。
和想法?

no star is displayed.only blank space. and ideas???

子类是在一个列表视图中。
  我想有它旁边的恒星列表视图的特定条件下一个项目,所以**我觉得我有code做下的。

推荐答案

您可以使用的android:drawableLeft 属性,在XML布局

you can use android:drawableLeft attribute in your xml layout.

http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableLeft

这篇关于Android的垂直的TextView与旁边的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆