gpt4 book ai didi

android - 是否可以在android的textview中垂直书写?

转载 作者:IT老高 更新时间:2023-10-28 22:00:48 27 4
gpt4 key购买 nike

假设您有一个普通的 TextView,其中写有“Stackoverflow”,是否可以将 TextView 旋转 -90°,使 S 位于屏幕底部,W 位于屏幕顶部?当然,我可以将我的文本写成图像,旋转它并以这种方式使用它,但我现在对文本感兴趣。谢谢。

最佳答案

你可以像往常一样设置你的 TextView

例如:

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

并在您的 Activity 中编写一个函数

  • 反转文本中的字符
  • 在每个字符后插入 \n

然后将文本设置到TextView。

如果您不想插入 \n,则必须设置 android:layout_width 的大小并调整字体大小,不要让 2 个字符适契约(Contract)一行,不截断

编辑如果我理解正确的话,你可以通过动画得到你想要的。

例如

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" />

您必须使用此文件来定义您希望放置 TextView 的位置。

在你的 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);

关于android - 是否可以在android的textview中垂直书写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2888780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com