ConstraintLayout不允许我设置将视图连接到屏幕边缘的约束

时间:2017-08-05 16:49:13

标签: android android-layout

Here's the image for what it looks like right now.我希望浮动操作按钮位于屏幕底部。 Here's me trying to do that.好的,所以这里是activity_main文件:

<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
    tools:context="com.example.jaden.finances.MainActivity">


    <android.support.v7.widget.Toolbar
        android:id="@+id/appBarLayout"
        android:layout_width="360dp"
        android:layout_height="81dp"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="40dp"
        android:layout_height="40dp"
        app:srcCompat="@android:drawable/ic_dialog_email"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:text="Name"
        android:ems="10"
        android:id="@+id/editText"
        android:hint="@string/edit_message"
        tools:layout_editor_absoluteY="83dp"
        tools:layout_editor_absoluteX="16dp" />

    <Button
        android:text="@string/button_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button3"
        android:onClick="sendMessage"
        tools:layout_editor_absoluteX="249dp"
        tools:layout_editor_absoluteY="81dp" />

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteY="126dp"
        tools:layout_editor_absoluteX="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/options">

        </LinearLayout>
    </ScrollView>
</android.support.constraint.ConstraintLayout>

我不确定我做错了什么。当我进入图形设计编辑器并单击并拖动边缘以创建新约束时,它将不会锁定到屏幕的边缘。谷歌搜索什么都不产生。

1 个答案:

答案 0 :(得分:2)

  

我将浮动操作按钮设置在屏幕底部。但是不知道滚动视图位置,所以我把它放在编辑文本下面。

<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
     tools:context=".MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/appBarLayout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginBottom="20dp"
    android:layout_marginRight="20dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:srcCompat="@android:drawable/ic_dialog_email" />

<EditText
    android:id="@+id/editText"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:ems="10"
    android:hint="Name"
    android:inputType="text"
    android:text="Name"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/appBarLayout" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="sendMessage"
    android:text="Send"
    app:layout_constraintLeft_toRightOf="@+id/editText"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="@+id/editText" />

<ScrollView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/editText">

    <LinearLayout
        android:id="@+id/options"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

    </LinearLayout>
</ScrollView>