无法在约束布局中移动简单按钮

6
我有一个约束布局定义,在里面有一个按钮。问题是我似乎无法移动按钮,因为它固定在屏幕的左上角。
需要帮助吗?

the button edges cant be dragged, it just sits there idle.

<android.support.constraint.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"
android:padding="16dp"
tools:context=".MainActivity">

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

你想通过编程移动它吗?还是从设计视图中移动? - Ümañg ßürmån
从设计视图来看,它在设计视图中就无法工作,这让人感到沮丧。 - Ryan Thompson
你还没有连接约束条件。请连接约束条件并拖动水平轴将按钮放置在正确位置。 - Ümañg ßürmån
尝试为按钮添加约束条件。 - Anisur Rahman Tonu
所有的那些功能都无法正常工作。 - Ryan Thompson
你能用 GIF 显示错误吗?似乎你的 IDE 出现了错误。 - Mohamed Mohaideen AH
3个回答

2

这对我很有帮助。 Android Studio -> Build -> Clean Project。


请添加更多细节以扩展您的答案,例如工作代码或文档引用。 - Community
这个可行!我也遇到了同样的问题,花了一个小时试图找出是否有什么遗漏...结果只是一个简单的错误。 - Calvin Ku

1
请使用设计选项卡或文本选项卡中的约束条件来定位小部件,并添加边距。以下为XML代码: app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent"
您可以在设计选项卡中添加边距(右上角的属性窗格),然后在文本选项卡中查看XML中的更改。
默认情况下,在约束布局中,任何未经约束的小部件都会落在右上角。

0

对于约束布局中的移动,您必须像下面的代码一样定义您的小部件: 此代码可以将您的小部件移动到屏幕右侧:

<Button
    android:id="@+id/img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginTop="10dp"
    />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接