【问题标题】:Constraintlayout and View Rotation not resizing Views约束布局和视图旋转不调整视图大小
【发布时间】: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"
  • 旋转只是一种效果,对布局参数没有影响。没有可以为您处理的布局,您必须手动计算并应用适当的 scaleXscaleY 以将视图限制在其范围内。

标签: android kotlin android-constraintlayout


【解决方案1】:

rotationtranslationXtranslationY的视图属性都是布局后生效的。我认为这适用于所有视图组。换句话说,视图的布局就像没有指定 rotation 一样。然后,在布局之后,应用旋转。这就是你所看到的。

我没有这方面的参考资料,但这个问题在 Stack Overflow 上经常出现。

Here 是一个使用 translationY 的示例。查看顶部的“澄清”部分。看看底部视图如何不移动,即使它被上面的视图从上到下约束?这是因为它定位到顶视图顶视图移动之前。 translationYrotation 一样发生在布局后。

这个问题可以通过(可能)一点编码来解决。确切的解决方案取决于您要执行的操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多