Constraintlayout (в RelativeLayout) layout_alignParentBottom вырезает снизу (в режиме приложения по умолчанию) - PullRequest
0 голосов
/ 24 сентября 2019

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

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

<RelativeLayout 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"
tools:context="org.cocos2dx.cpp.AppActivity"
android:id="@+id/cameraView">

  <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/control"
    android:layout_width="match_parent"
    android:layout_height="112dp"
    android:paddingBottom="0dp"
    android:layout_alignParentBottom="true"
    android:background="@color/control_background">

     <ImageButton
        android:id="@+id/cancelBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="30dp"
        android:layout_marginLeft="30dp"
        android:background="@android:color/transparent"
        android:src="@drawable/close"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageButton
        android:id="@+id/imageCaptureBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@android:color/transparent"
        android:scaleX="1.20"
        android:scaleY="1.20"
        android:src="@drawable/capture"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.5" />

    <ImageButton
        android:id="@+id/reverseCameraBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|right"
        android:layout_marginEnd="30dp"
        android:layout_marginRight="30dp"
        android:background="@android:color/transparent"
        android:src="@drawable/reverse_cam"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.508" />

</androidx.constraintlayout.widget.ConstraintLayout>

</RelativeLayout>

Итак, здесь, в ConstraintLayout, когда я сохраняю

android: layout_alignParentTop = "true"

Он не вырезается сверху, как на изображении enter image description here

, но когда я передаю его на android: layout_alignParentBottom = "true", он обрезается только в режиме приложения по умолчанию, и я хочу, чтобы этот constraintLayout находился в нижней части RelativeLayout enter image description here

1 Ответ

0 голосов
/ 24 сентября 2019

Вы также можете использовать макет ограничения в качестве Rootview, как показано ниже.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/cameraView">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/control"
        android:layout_width="match_parent"
        android:layout_height="112dp"
        android:layout_alignParentBottom="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background="@color/colorPrimary">

        <ImageButton
            android:id="@+id/cancelBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginStart="30dp"
            android:layout_marginLeft="30dp"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_attach"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/imageCaptureBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@android:color/transparent"
            android:scaleX="1.20"
            android:scaleY="1.20"
            android:src="@drawable/ic_attach"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <ImageButton
            android:id="@+id/reverseCameraBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_attach"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:ignore="RtlHardcoded" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
...