Макет ограничения приводит к перекрытию представлений - PullRequest
0 голосов
/ 31 мая 2018

Я пытаюсь создать представление в Android, используя ConstraintLayout, но у меня много проблем с перекрывающимися или выталкивающимися видами экрана.Я думаю, что многое из этого может быть, потому что я так привык к ограничениям iOS, и я думаю о них.Вот мой код:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".LocationFragment">

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/guideHorz125"
        app:layout_constraintGuide_percent="0.125"/>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/guideHorz875"
        app:layout_constraintGuide_percent="0.875"/>

    <TextView style="@style/Label"
        android:id="@+id/currentSelectionLabel"
        android:layout_marginBottom="21dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="11dp"
        android:text="@string/current_selection"
        app:layout_constraintBottom_toTopOf="@id/locationLabel"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView style="@style/Label"
        android:id="@+id/locationLabel"
        android:layout_marginLeft="41dp"
        android:text="@string/none"
        app:layout_constraintBottom_toTopOf="@id/mapView"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/currentSelectionLabel"/>

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        app:layout_constraintBottom_toTopOf="@id/previousButton"
        app:layout_constraintDimensionRatio="16:9"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/locationLabel"/>

    <Button style="@style/RoundedButton"
        android:id="@+id/previousButton"
        android:text="@string/previous"
        app:layout_constraintBottom_toTopOf="@id/newButton"
        app:layout_constraintLeft_toLeftOf="@id/guideHorz125"
        app:layout_constraintRight_toRightOf="@id/guideHorz875"
        app:layout_constraintTop_toBottomOf="@id/mapView"/>

    <Button style="@style/RoundedButton"
        android:id="@+id/newButton"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/new_location"
        app:layout_constraintBottom_toTopOf="@id/resetButton"
        app:layout_constraintLeft_toLeftOf="@id/previousButton"
        app:layout_constraintRight_toRightOf="@id/previousButton"
        app:layout_constraintTop_toBottomOf="@id/previousButton"/>

    <Button style="@style/RoundedButton"
        android:id="@+id/resetButton"
        android:text="@string/reset"
        app:layout_constraintBottom_toTopOf="@id/startButton"
        app:layout_constraintLeft_toLeftOf="@id/previousButton"
        app:layout_constraintRight_toRightOf="@id/previousButton"
        app:layout_constraintTop_toBottomOf="@id/previousButton"/>

    <com.company.ui.ImageButton
        android:id="@+id/startButton"
        android:layout_width="240dp"
        android:layout_height="90dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="11dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:src="@drawable/start"
        app:text="@string/get_started"/>
</android.support.constraint.ConstraintLayout>

Первое изображение - это то, что я хотел бы видеть, а второе - то, что я получаю. enter image description here enter image description here

Ответы [ 2 ]

0 голосов
/ 06 июня 2018

Использовать ниже макет:

<?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.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="4dp"
                android:text="Current Selection"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:text="None"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.184"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView3" />

            <com.google.android.gms.maps.MapView
                android:id="@+id/mapView"
                android:layout_width="311dp"
                android:layout_height="114dp"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView4" />

            <Button
                android:id="@+id/button54"
                android:layout_width="296dp"
                android:layout_height="36dp"
                android:layout_marginTop="52dp"
                android:text="Button"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/mapView" />

            <Button
                android:id="@+id/button55"
                android:layout_width="296dp"
                android:layout_height="36dp"
                android:layout_marginTop="96dp"
                android:text="Button"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/mapView" />

            <Button
                android:id="@+id/button56"
                android:layout_width="296dp"
                android:layout_height="36dp"
                android:layout_marginTop="8dp"
                android:text="Button"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/mapView" />

            <ImageButton
                android:id="@+id/imageButton"
                android:layout_width="293dp"
                android:layout_height="116dp"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.5"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button55"
                app:layout_constraintVertical_bias="0.529"
                app:srcCompat="@drawable/googleg_disabled_color_18" />
        </android.support.constraint.ConstraintLayout>

    </android.support.v4.widget.NestedScrollView>

</android.support.constraint.ConstraintLayout> 
0 голосов
/ 31 мая 2018

Попробуйте изменить

 <Button style="@style/RoundedButton"
    android:id="@+id/resetButton"
    android:text="@string/reset"
    app:layout_constraintBottom_toTopOf="@id/startButton"
    app:layout_constraintLeft_toLeftOf="@id/previousButton"
    app:layout_constraintRight_toRightOf="@id/previousButton"
    app:layout_constraintTop_toBottomOf="@id/previousButton"/>

На

 <Button style="@style/RoundedButton"
    android:id="@+id/resetButton"
    android:text="@string/reset"
    app:layout_constraintBottom_toTopOf="@id/startButton"
    app:layout_constraintLeft_toLeftOf="@id/previousButton"
    app:layout_constraintRight_toRightOf="@id/previousButton"
    app:layout_constraintTop_toBottomOf="@id/newButton"/>
...