java - TextView 中的旋转问题

标签 java android xml layout

我的问题是我想在 FrameLayout 内旋转 TextView,但无法旋转 FrameLayout

当我将 TextView 旋转 90 度时,它与父级不匹配! 但我需要文本填写所有家长!

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/FLback"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/FLitem"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="1dp">

        <TextView
            android:id="@+id/TVitem"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="4dp"
            android:background="@color/colorPrimaryDark"
            android:gravity="center"
            android:rotation="90"
            android:text="TEXT"
            android:textColor="@android:color/black"
            android:textSize="10sp" />
    </FrameLayout>
</FrameLayout>

这里是问题所在的示例:

/image/OuzZZ.jpg

问题就在一张照片中!

谢谢!

最佳答案

问题是 Android 首先会测量 View ,然后才会旋转它。所以,我想你仍然应该旋转你的 TextView ,但如果你想要一个漂亮的背景 - 你应该为父 View 设置背景。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/FLback"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark">

    <FrameLayout
        android:id="@+id/FLitem"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="1dp">

        <TextView
            android:id="@+id/TVitem"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="4dp"
            android:gravity="center"
            android:rotation="90"
            android:text="TEXT"
            android:textColor="@android:color/black"
            android:textSize="10sp" />
    </FrameLayout>
</FrameLayout>

关于java - TextView 中的旋转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56041485/

相关文章:

java - 蓝牙键盘的协议(protocol)?

java - Listview删除项目和刷新 - android

java - 从数据处理程序写入文件

Android Studio 打开 fragment 但不更改底部导航菜单状态

python - 用 python 解析 lxml : how to with objectify

ruby - 如何使用 Hadoop 将 XML 转换为 TSV?

java - length开头的json是什么类型的

android - 如何处理ListView中的多次点击?

android - 我在 Cordova 中哪里编辑插件 Java 代码?

java - CAMT.053 Java 解析器