约束布局和视图旋转不调整视图大小

问题描述 投票:0回答:1

我使用带有偏见的约束布局来用多个视图填充屏幕。当我旋转视图时,它们不会调整大小以填充屏幕。我的布局更加复杂,但是我创建了一个示例来展示我的问题。

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

Screen

我旋转外部或内部FrameLayout并不重要。我不认为我在LinearLayouts上遇到过这个问题,也许旋转使约束变得混乱了吗?

编辑:嗯,当使用以重量为父级的Linearlayout时,发生的情况相同,因此Im可能在这里做错了。

android kotlin android-constraintlayout
1个回答
0
投票

[translationXtranslationY的视图属性均在布局后生效。我认为所有视图组都是如此。换句话说,视图的布局就像未指定rotation一样。然后,在布局之后,应用旋转。这就是您所看到的。

我对此没有参考,但是这个问题在Stack Overflow上出现了很多。

Here是使用

translationY

的示例。查看顶部的“说明”部分。看到底视图从上到下受约束时,底视图如何不移动?那是因为它位于顶视图之前顶视图移动的位置。 translationYrotation一样在布局后发生。可以(可能)只需少量编码即可解决此问题。确切的解决方案取决于您要执行的操作。
© www.soinside.com 2019 - 2024. All rights reserved.