Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 拖放constraintlayout中的视图将视图移动到左上角_Android_Android Studio_Android Layout_Android Constraintlayout - Fatal编程技术网

Android 拖放constraintlayout中的视图将视图移动到左上角

Android 拖放constraintlayout中的视图将视图移动到左上角,android,android-studio,android-layout,android-constraintlayout,Android,Android Studio,Android Layout,Android Constraintlayout,我不熟悉约束布局,在阅读文档后,我知道视图必须有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:

我不熟悉约束布局,在阅读文档后,我知道视图必须有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布局编辑器特有的错误。你试过运行应用程序并看到了吗?还可以尝试选择文件>使缓存无效/Restart@SyedAhmedJamil你确定这是个bug而不是我这边的问题吗?是的,有时候会发生。布局编辑器试图显示您运行应用程序后将看到的输出,但并非始终100%准确。你有没有试过运行这个应用程序,看看在应用程序运行的时候,你的视图实际上在哪里?我知道它会显示在应用程序的正确位置,但这就是ConstraintLayout用来简化设计过程的意思,这就是为什么我说它是一个bug。尝试进入文件>无效缓存/重新启动或更新android studio。你用的是什么版本?