0

will it be possible to display text in diagonal way if yes then how can we implement, please help me out for this thanks. i have added image i have to replace WORLD text with other text.

enter image description here

chet's
  • 193
  • 2
  • 8

4 Answers4

1

Look here: How to Rotate TextView 90 Degrees and display.

The easiest way to do this is to:

  1. Create TextView with your background image.
  2. Rotate TextView as it is done in link above.
Community
  • 1
  • 1
Ari
  • 3,101
  • 2
  • 27
  • 49
1

If you are using API 11 or later, you may try:

TextView tv = (TextView) findViewById(R.id.txtview);
String txt = "Stackoverflow";         
tv.setText(txt);
tv.setRotation(45); // 45 degree rotation

Try this..

Lal
  • 14,726
  • 4
  • 45
  • 70
0

Use android:rotation in XML

or

textView.setRotation(angle)

http://developer.android.com/reference/android/view/View.html#attr_android:rotation

AndroidDev
  • 5,193
  • 5
  • 37
  • 68
-1

Guys i have implemented with custom textview thanks for your valuable response.working well on 4.0 device need to test it on 2.2 device.

    public class DiagonalTextView extends TextView{
   final boolean topDown;

   public DiagonalTextView(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 boolean setFrame(int l, int t, int r, int b){
      return super.setFrame(l, t, l+(b-t), t+(r-l));
   }

   @Override
   public void draw(Canvas canvas){
      if(topDown){
         canvas.translate(getHeight(), 0);
         canvas.rotate(45);
      }else {
         canvas.translate(0, getWidth());
         canvas.rotate(-45);
      }
      canvas.clipRect(0, 0, getWidth(), getHeight(), android.graphics.Region.Op.REPLACE);
      super.draw(canvas);
   }
}
chet's
  • 193
  • 2
  • 8