为什么我的ImageView出现在顶部?

时间:2018-03-14 23:20:11

标签: android xml android-layout android-studio

我对Android很新,并且一直在关注相机应用程序的简单教程。它在FrameLayout(向上)中显示相机的预览,然后在点击FrameLayout正下方的按钮后捕获图像。然后,图像显示在应该位于按钮下方的Im​​ageView中。但是,当我运行程序并单击按钮拍照时,捕获的图像显示在FrameLayout的TOP上。我已经尝试在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" />

我能做些什么来解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

如果您希望imageView显示在Button和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" />

干杯!

相关问题