首页 > 解决方案 > 无法在 Android Studio 中为 RelativeLayout 移动任何元素

问题描述

我正在尝试将一些按钮/文本视图或任何其他组件添加到我的相对布局中。除了左上角,我不能把它们放在任何地方。但是,如果我编辑 XML 代码,它可以正常工作。

这是当前状态的截图

我已经将布局更改为 relativeLayout 但仍然没有运气。(安卓工作室 3.3)

我的布局 xml 是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/activity_main"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</RelativeLayout>

我希望将这些按钮/文本视图相对于彼此移动,但它们只是停留在左上角。

标签: androidandroid-layoutandroid-relativelayout

解决方案


视图编辑器顶部有一个磁性按钮,称为(开/关自动连接)。如果你改变它,你可以在相对布局中移动视图。


推荐阅读