我的问题是我想在 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>
这里是问题所在的示例:
问题就在一张照片中!
谢谢!
最佳答案
问题是 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/