【发布时间】:2019-04-16 15:53:16
【问题描述】:
视图不受限制。它只有设计时位置,所以它会在运行时跳转到 (0,0)
这些属性不会在运行时应用,因此如果您在设备上推送布局,小部件可能会出现在与编辑器中显示的位置不同的位置。
【问题讨论】:
-
你添加了约束吗?如果您有,请更具体地说明问题和显示异常的图像。
视图不受限制。它只有设计时位置,所以它会在运行时跳转到 (0,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了解更多信息。
【讨论】: