旋转后TextView的文本缺少字符

时间:2019-06-04 08:41:28

标签: java android xml layout

我想在我的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"/>

旋转完成了,但是只显示了那些无需旋转就可以看到的字符-但是有足够的空间来显示所有字符。有人有主意吗?

1 个答案:

答案 0 :(得分:0)

我认为这确实是一个错误,但是我找到了一个自己没有自定义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(目标位置)。