【发布时间】:2020-05-17 23:06:39
【问题描述】:
我使用带偏差的约束布局来填充屏幕的多个视图。当我旋转视图时,它们不会调整大小以填充屏幕。我的布局更复杂,但我创建了一个示例来展示我的问题。
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/one"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/holo_orange_dark"
app:layout_constraintBottom_toTopOf="@+id/two"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rotation="90"
android:background="@android:color/holo_green_light"/>
</FrameLayout>
<FrameLayout
android:id="@+id/two"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/holo_red_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/one">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
旋转外部或内部 FrameLayout 并不重要。我不认为我对 LinearLayouts 有这个问题,也许约束被旋转弄乱了?
编辑:嗯,当使用以权重为父级的 Linearlayout 时,似乎发生了同样的情况,所以我可能只是在这里做错了。
【问题讨论】:
-
旋转视图是什么意思?通过设备旋转或其他方式旋转视图?
-
android:rotation="90"
-
旋转只是一种效果,对布局参数没有影响。没有可以为您处理的布局,您必须手动计算并应用适当的
scaleX和scaleY以将视图限制在其范围内。
标签: android kotlin android-constraintlayout