无法在约束布局周围移动简单的按钮

时间:2018-10-07 03:09:37

标签: java android android-studio mobile s

我定义了一个约束布局,在其中有一个按钮。问题是由于固定在屏幕的左上方,我似乎无法左右移动按钮。

有帮助吗?

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" />

2 个答案:

答案 0 :(得分: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"
    />

答案 1 :(得分:0)

除了添加边距之外,请在设计选项卡或文本选项卡中使用约束来定位小部件。 XML代码: app:layout_constraintTop_toTopOf =“ parent” app:layout_constraintLeft_toLeftOf =“ parent”

您可以在“设计”选项卡(右上角的属性窗格)中添加边距,然后在“文本”选项卡中查看添加的XML,以查看XML中的更改。

默认情况下,在“约束”布局中,任何不受限制的窗口小部件都位于右上方。

相关问题