Почему мой ImageView отображается вверху?

Я очень новичок в Android и следую простому руководству по приложению камеры. Он показывает предварительный просмотр камеры в FrameLayout (вверху), а затем захватывает изображение после нажатия кнопки непосредственно под FrameLayout. Затем изображение отображается в ImageView, который должен находиться под кнопкой. Однако, когда я запускаю программу и нажимаю кнопку, чтобы сделать снимок, захваченное изображение появляется в ТОПе FrameLayout. Я попытался исправить это на вкладке дизайна в activity_main.xml, но, похоже, я не могу найти ImageView в дизайне, даже если он указан в моем дереве компонентов.

Вот три компонента из моего файла xml:

    <Button
    android:id = "@+id/button"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_below = "@+id/camera_preview"
    android:layout_centerHorizontal = "true"
    android:layout_marginBottom = "8dp"
    android:layout_marginEnd = "8dp"
    android:layout_marginStart = "8dp"
    android:layout_marginTop = "8dp"
    android:text = "@string/capture_button"
    app:layout_constraintBottom_toBottomOf = "parent"
    app:layout_constraintEnd_toEndOf = "parent"
    app:layout_constraintStart_toStartOf = "parent"
    app:layout_constraintTop_toBottomOf = "@+id/text"
    app:layout_constraintVertical_bias = "0.143" />

<FrameLayout
    android:id = "@+id/camera_preview"
    android:layout_width = "match_parent"
    android:layout_height = "300dp"/>

<ImageView
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content"
    android:id = "@+id/captured_image"
    android:layout_below = "@+id/button"
    android:layout_alignParentLeft = "true"
    android:layout_alignParentRight = "true"
    android:layout_marginBottom = "15dp"
    android:contentDescription = "@string/desc" />

Что я могу сделать, чтобы это исправить?

Вы хотите, чтобы ImageView отображался под кнопкой?

Niamatullah Bakhshi 15.03.2018 00:32
0
1
36
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Если вы хотите, чтобы ваш imageView отображался под кнопками и FrameLayout

Добавьте это в свой тег FrameLayout

android:layout_below = "@id/button"

Ваш отредактированный код.

<Button
    android:id = "@+id/button"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_below = "@+id/camera_preview"
    android:layout_centerHorizontal = "true"
    android:layout_marginBottom = "8dp"
    android:layout_marginEnd = "8dp"
    android:layout_marginStart = "8dp"
    android:layout_marginTop = "8dp"
    android:text = "@string/capture_button"
    app:layout_constraintBottom_toBottomOf = "parent"
    app:layout_constraintEnd_toEndOf = "parent"
    app:layout_constraintStart_toStartOf = "parent"
    app:layout_constraintTop_toBottomOf = "@+id/text"
    app:layout_constraintVertical_bias = "0.143" />

<FrameLayout
android:id = "@+id/camera_preview"
android:layout_width = "match_parent"
android:layout_height = "300dp"
android:layout_below = "@id/button"
    />

<ImageView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:id = "@+id/captured_image"
android:layout_below = "@+id/camera_preview"
android:layout_alignParentLeft = "true"
android:layout_alignParentRight = "true"
android:layout_marginBottom = "15dp"
android:contentDescription = "@string/desc" />

Ваше здоровье!

Другие вопросы по теме