有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在TextView中的旋转问题

我的问题是我想在FrameLayout内旋转TextView,但我不能旋转FrameLayout

当我将TextView旋转90度时,它与父对象不匹配! 但我需要给所有家长发短信

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

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

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

这里有一个问题的例子:

https://imgur.com/mQSvANK

一张照片中的问题

谢谢


共 (2) 个答案

  1. # 1 楼答案

    谢谢你的帮助

    我找到的解决方案是测量整个视图并更改Textview的大小

    谢谢

  2. # 2 楼答案

    问题是Android首先会测量视图,然后才会旋转视图。所以,我想你仍然应该旋转你的文本视图,但是如果你想要一个好的背景,你应该为父视图设置背景

    <?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>