app: layout_constraintBottom_toBottomOf = "parent" для раздутого макета XML - PullRequest
0 голосов
/ 28 октября 2018

enter image description here

Я накачал макет XML поверх холста Views. Кнопки «Button to Bottom» Я ожидаю, что они должны быть привязаны к нижней части экрана, однако приложение: layout_constraintBottom_toBottomOf = "parent" не работает.

Как получить нижнюю линейную компоновку для привязки к нижней части экрана и верхнюю линейную компоновку для привязки к верхней части экрана?

Вот XML:

                <?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:id="@+id/constlayout_matchreplay_actionbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="visible">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <Button
                        android:id="@+id/button_matchreplay_back"
                        android:layout_width="150dip"
                        android:layout_height="50dip"
                        android:text="back" />

                    <Spinner
                        android:id="@+id/spinner_matchreplay_matchselect"
                        android:layout_width="200dip"
                        android:layout_height="45dip"
                        android:background="@android:drawable/btn_dropdown"
                        android:spinnerMode="dropdown" />

                    <Button
                        android:id="@+id/button_matchreplay_forward"
                        android:layout_width="150dip"
                        android:layout_height="50dip"
                        android:text="forward" />

                    <Button
                        android:id="@+id/button_matchreplay_empty_room"
                        android:layout_width="75dip"
                        android:layout_height="50dip"
                        android:text="DELETE"
                        android:textSize="8dip" />

                    <Button
                        android:id="@+id/button_matchreplay_empty_all"
                        android:layout_width="75dip"
                        android:layout_height="50dip"
                        android:text="EMPTY-ALL"
                        android:textSize="8dip" />


                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginBottom="8dp"
                    android:orientation="horizontal"
                    android:visibility="visible"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent">

                    <Button
                        android:id="@+id/button4"
                        android:layout_width="150dip"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Button to Bottom" />

                    <Button
                        android:id="@+id/button5"
                        android:layout_width="150dip"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Button to Bottom" />
                </LinearLayout>




            </android.support.constraint.ConstraintLayout>

Ответы [ 2 ]

0 голосов
/ 28 октября 2018

Желательно не использовать LinearLayout внутри ConstraintLayout, так как ConstraintLayout позволяет создавать большие и сложные макеты с иерархией плоского вида ( без вложенных групп видов ).

Пожалуйста, попробуйте следующий подход

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


    <Button
        android:id="@+id/button_matchreplay_back"
        android:layout_width="150dip"
        android:layout_height="50dip"
        android:layout_marginTop="5dp"
        android:text="back"
        app:layout_constraintEnd_toStartOf="@+id/spinner_matchreplay_matchselect"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Spinner
        android:id="@+id/spinner_matchreplay_matchselect"
        android:layout_width="200dip"
        android:layout_height="45dip"
        android:layout_marginStart="10dp"
        android:layout_marginTop="5dp"
        android:background="@android:drawable/btn_dropdown"
        android:spinnerMode="dropdown"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button_matchreplay_back"
        app:layout_constraintTop_toTopOf="parent" />


    <Button
        android:id="@+id/button_matchreplay_forward"
        android:layout_width="150dip"
        android:layout_height="50dip"
        android:layout_marginTop="15dp"
        android:text="forward"
        app:layout_constraintEnd_toStartOf="@+id/button_matchreplay_empty_all"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button_matchreplay_back" />

    <Button
        android:id="@+id/button_matchreplay_empty_all"
        android:layout_width="75dip"
        android:layout_height="50dip"
        android:layout_marginStart="10dp"
        android:layout_marginTop="15dp"
        android:text="EMPTY-ALL"
        android:textSize="8dip"
        app:layout_constraintEnd_toStartOf="@+id/button_matchreplay_empty_room"
        app:layout_constraintStart_toEndOf="@+id/button_matchreplay_forward"
        app:layout_constraintTop_toBottomOf="@+id/button_matchreplay_back" />

    <Button
        android:id="@+id/button_matchreplay_empty_room"
        android:layout_width="75dip"
        android:layout_height="50dip"
        android:layout_marginStart="10dp"
        android:layout_marginTop="15dp"
        android:text="DELETE"
        android:textSize="8dip"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button_matchreplay_empty_all"
        app:layout_constraintTop_toBottomOf="@+id/button_matchreplay_back" />


    <Button
        android:id="@+id/button5"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:text="Button to Bottom"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/button4"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent" />

    <Button
        android:id="@+id/button4"
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginBottom="5dp"
        android:text="Button to Bottom"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/button5" />


</android.support.constraint.ConstraintLayout>

Пожалуйста, см. Ниже последний скриншот макета выше XML

Constraint layout Для получения дополнительной информации см ConstraintLayout

0 голосов
/ 28 октября 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"
    android:id="@+id/constlayout_matchreplay_actionbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <Button
            android:id="@+id/button_matchreplay_back"
            android:layout_width="150dip"
            android:layout_height="50dip"
            android:text="back" />

        <Spinner
            android:id="@+id/spinner_matchreplay_matchselect"
            android:layout_width="200dip"
            android:layout_height="45dip"
            android:background="@android:drawable/btn_dropdown"
            android:spinnerMode="dropdown" />

        <Button
            android:id="@+id/button_matchreplay_forward"
            android:layout_width="150dip"
            android:layout_height="50dip"
            android:text="forward" />

        <Button
            android:id="@+id/button_matchreplay_empty_room"
            android:layout_width="75dip"
            android:layout_height="50dip"
            android:text="DELETE"
            android:textSize="8dip" />

        <Button
            android:id="@+id/button_matchreplay_empty_all"
            android:layout_width="75dip"
            android:layout_height="50dip"
            android:text="EMPTY-ALL"
            android:textSize="8dip" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:orientation="horizontal"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <Button
            android:id="@+id/button4"
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button to Bottom" />

        <Button
            android:id="@+id/button5"
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button to Bottom" />
    </LinearLayout>

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