如何解决约束布局中缺少约束的问题

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

视图不受约束。它只有设计时间位置,因此它会在运行时跳转到(0,0) 这些属性不会在运行时应用,因此如果您在设备上推送布局,则窗口小部件可能显示在与编辑器中显示的位置不同的位置。

android-constraintlayout
1个回答
0
投票

您需要为视图提供垂直和水平约束,因此在运行时,它将具有相对于屏幕的位置。如果您不这样做,您的视图将没有垂直/水平位置,并且如果屏幕将从其位置跳到开始。

你可以这样做,例如:

   <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

此外,您可以查看官方documentation了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.