[英]Why does my ImageView appear at the top?
我是android的新手,一直在关注相机应用程序的简单教程。 它在FrameLayout中(朝顶部)显示摄像机的预览,然后在直接单击FrameLayout下方的按钮后捕获图像。 然后,图像将显示在应该位于按钮下方的ImageView中。 但是,当我运行程序并单击按钮拍照时,捕获的图像将显示在FrameLayout的TOP上。 我曾尝试在activity_main.xml的设计选项卡中修复此问题,但即使它在组件树中列出,我似乎也无法在设计中找到它。
这是我的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出现在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" />
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.