【问题标题】:Text of TextView after rotation is missing characters旋转后TextView的文本缺少字符
【发布时间】:2019-06-04 08:41:28
【问题描述】:

我想在我的 Android 布局中使用文本视图,文本应该向左旋转 90 度。文本视图的宽度相当小(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"/>

旋转完成,但只显示那些在没有旋转的情况下可见的字符 - 但有足够的空间显示所有这些字符。有人有想法吗?

【问题讨论】:

  • 尝试将layout_height设置为wrap_content
  • 这是一个很奇怪的问题。我在我的 Android Studio Preview 部分尝试过,由于某种原因它不能正常工作。也许是一个错误?
  • 感谢您的想法,但这会导致文本中出现换行符 :-(
  • 感谢 Vedprakash 检查此问题不仅发生在我的系统上...
  • 您可以使用自定义 TextView :here

标签: java android xml layout


【解决方案1】:

我认为这确实是一个错误,但我自己找到了一个没有自定义 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" />

诀窍是将最小和最大宽度设置为允许文本不会以水平对齐方式剪切的值。布局高度必须设置为您想要的高度。高度属性必须设置为文本视图的目标宽度。以下文本视图必须包含 android:layout_marginLeft="-20dp" 以确保它向左移动 20 dp(目标位置)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    相关资源
    最近更新 更多