【发布时间】:2020-03-22 11:47:25
【问题描述】:
我是约束布局的新手,在阅读文档后我知道视图必须有 1 个水平和 1 个垂直坐标,但是每当我将新视图拖入设计时,它就会移动到 0,0 坐标
我的 XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="181dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/imageView3"
app:layout_constraintEnd_toEndOf="@+id/imageView3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_add_friend" />
</androidx.constraintlayout.widget.ConstraintLayout>
我已经设置了视图垂直和水平约束,但它仍然挂在左上角也尝试了垂直和水平偏差但视图粘在左上角。请帮助
【问题讨论】:
-
它是一个 android studio 布局编辑器特定的 bug。您是否尝试过运行该应用程序并查看?也尝试选择 File > Invalidate Caches/Restart
-
@SyedAhmedJamil 你确定这是一个错误而不是我这边的问题吗?
-
是的,有时会发生。布局编辑器会尝试显示运行应用程序后您将看到的输出,但它并非始终 100% 准确。您是否尝试过运行应用程序并查看应用程序运行时实际查看的位置?
-
我知道它会显示在应用程序的正确位置,但这就是 constrainlayout 旨在简化设计过程的意义
-
这就是为什么我说这是一个错误。尝试去 File > Invalidate Caches/Restart 或更新您的 android studio。你用的是什么版本?
标签: android android-studio android-layout android-constraintlayout