是否可以在android的textview中垂直书写? [英] Is it possible to write vertically in a textview in android?
问题描述
假设您有一个普通的 TextView,其中写有Stackoverflow",是否可以将 TextView 旋转 -90°,使 S 位于屏幕底部,W 位于屏幕顶部?当然,我可以将我的文本写成图像,旋转它并以这种方式使用它,但我现在对文本感兴趣.谢谢.
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.
推荐答案
你可以像平常一样设置你的textview
You can set your textview as you would normally do
例如:
<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
然后将文本设置到TextView.
and then set the text to the TextView.
如果您不想插入
,则必须设置 android:layout_width
的大小并调整字体大小,不要让 2 个字符适合同一行,不截断
If you dont want to insert the
, 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.
例如
在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.
在你的活动中:
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);
这篇关于是否可以在android的textview中垂直书写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!