Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write vertically in a textview in android?

Let's say you have a normal TextView, with "Stackoverflow" written in it, Is it possible to rotate the TextView by -90°, to have the S at the bottom and the W at the top of the screen? Of course I could write my text as an image, rotate it and use it that way, but I am interested in the text right now. Thanks.

like image 828
Sephy Avatar asked May 22 '10 16:05

Sephy


People also ask

How do I make TextView vertical?

Implement vertical TextView by calling setRotation() We can call the method of TextView object to make it display in vertical. Java code, call setRotation() to display the TextView (verticalTextView) in vertical. remark: Have to modify AndroidManifest. xml to set android:minSdkVersion="11" or higher.

What is a TextView in android?

A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.

How do you write vertically in Miro?

Simply type the text, then click and drag over the rotation arrow, which will be on the bottom left corner.

How do you add a line in TextView?

If you just want to add a line break in the form: textView. setText(string1+System. getProperty ("line. separator")+string2); then it works a treat, thank you!


1 Answers

You can set your textview as you would normally do

for example:

 <TextView android:id="@+id/txtview"     android:layout_height="fill_parent"     android:layout_width="wrap_content" /> 

and write a function in your activity to

  • reverse the characters in your text
  • insert \n after every characters

and then set the text to the TextView.

If you dont want to insert the \n, you will have to set the size of android:layout_width and play with font size not to have 2 characters fitting on the same line and no truncation

Edit If I have understood you correctly, you can get what you want by using animation.

For example

Under res/anim/myanim.xml:

<rotate  xmlns:android="http://schemas.android.com/apk/res/android"            android:fromDegrees="0"             android:toDegrees="-90"            android:pivotX="50%"            android:duration="0" /> 

You will have to play with this file to define where you want your text view to be placed.

In your activity:

  TextView t = (TextView)findViewById(R.id.txtview);   String txt = "Stackoverflow";            t.setText(txt);    RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);   ranim.setFillAfter(true); //For the textview to remain at the same place after the rotation   t.setAnimation(ranim); 
like image 173
ccheneson Avatar answered Sep 20 '22 17:09

ccheneson