android 如何在 Recyclerview 的 Textview 中垂直显示文本?

How to show text verttically in Textview in Recyclerview in android?

我想在 recyclerview.I 中显示名称列表为 that.But 设计了 ​​Recyclerview 项目 xml 问题是我想在单行中垂直显示这些名称(从下到上)。

我已经尝试通过更改 TextView.But 的角度(旋转属性),它在 Recyclerview 上不起作用。 有人可以帮我解决这个问题吗?

我发现解决方案 finally.I 必须创建一个自定义 class 扩展 TextView。我们可以通过这个实现我们的目标。

这是我的 class:

public class NewVerticalView extends TextView {
    private Rect bounds = new Rect();
    private TextPaint textPaint;
    private int color;

    public NewVerticalView(Context context) {
        super(context);
    }

    public NewVerticalView(Context context, AttributeSet attrs) {
        super(context, attrs);
        color = getCurrentTextColor();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        textPaint = getPaint();
        textPaint.getTextBounds((String) getText(), 0, getText().length(), bounds);
        setMeasuredDimension((int) (bounds.height() + textPaint.descent()), bounds.width());
    }

    @Override
    protected void onDraw(Canvas canvas) {
        textPaint.setColor(color);
        canvas.rotate(-90,bounds.width(),0
        );
        canvas.drawText((String) getText(), 0,- bounds.width() + bounds.height(), textPaint);
    }
}