you want to display the vertical text in the picture

used this option to implement vertical textview

http://developer.alexanderklimov.ru/android/views/verticaltextview.php

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

Faced a problem:

if TextView has a background color, the text is displayed on a colored rectangle.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <test.VerticalTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="bottom|right" android:text="Hello" android:background="#00FF00" /> </LinearLayout> 

enter image description here

But if you set an image as a background, then it is deformed, getting a width equal to the length of the inscription. How to fix it?

enter image description here

PS The original image for the background has the same width as the green stripe in the first picture

added:

in the proposed version of the vertical TextView, the output area becomes square, and since for the bitmap property gravity = fill, the background is deformed

question: how to trim the width of the output area to the height of the font, so that the area was not square, but rectangular as in this image?

enter image description here

Is it possible to override the methods of the parent class, so that the width and height of the TextView are equal to the original background image?

  • Try setting the TextView attribute adjustViewBounds = "true" - alex11
  • @ alex11, did not help ( - ravend
  • The original image is the same width as the green bar. And what is its height? Perhaps it simply stretches to the full height of the text - and proportionally stretches to the width. - Aleks G
  • @AleksG, the size of the original image 22h65px, the size of the green substrate 30h54px. It seems to me that the picture is stretched to the width of the text in a horizontal position. But I do not understand how to fix it. - ravend

0