是否有可能在Android的一个TextView垂直写? [英] Is it possible to write vertically in a textview in android?
问题描述
让我们假设你有一个正常的TextView,以#1写在上面,是否有可能由-90°旋转TextView的,有电子的底部,并在屏幕的顶部将出现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 E 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 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
\n
after every characters
,然后设置文字的TextView的。
and then set the text to the TextView.
如果你不想插入 \ñ
,你必须设置机器人的大小:layout_width
和字体大小玩不要有2个字符在同一行拟合和没有截断
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.
例如
在 RES /动画/ 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屋!