我想在 Android 布局中使用 TextView ,文本应向左旋转 90 度。 TextView 的宽度相当小(20dp)。我的代码如下所示:
<TextView
android:id="@+id/txtVw"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:minWidth="20dp"
android:maxWidth="20dp"
android:paddingEnd="6dp"
android:rotation="270"
android:text="Test"/>
旋转已完成,但仅显示那些无需旋转即 cocoa 见的字符 - 但有足够的空间来显示所有字符。有人有想法吗?
最佳答案
我认为这确实是一个错误,但我自己找到了一个没有自定义 TextView 的解决方案 - 如果其他人需要此解决方案,我会将其发布:
<TextView
android:id="@+id/txtVwOne"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:height="20dp"
android:gravity="end"
android:maxWidth="40dp"
android:minWidth="40dp"
android:rotation="270"
android:text="Test" />
<TextView
android:id="@+id/txtVwTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_weight="1"
android:layout_marginLeft="-20dp"
android:minHeight="40dp" />
诀窍是将最小和最大宽度设置为一个值,该值将允许文本在水平对齐时不会被剪切。布局高度必须设置为您想要的高度。高度属性必须设置为 TextView 的目标宽度。以下 TextView 必须包含 android:layout_marginLeft="-20dp"
以确保其向左移动 20 dp(目标位置)。
关于java - 旋转后TextView的文本缺少字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56440317/