【发布时间】:2016-03-08 21:21:08
【问题描述】:
我有以下LinearLayout,其中包含一个摄像头源预览,以及一个在摄像头预览之上绘制的叠加层。预览是全屏的。
现在,当我尝试添加ImageButton 以切换正在使用的设备摄像头(前/后)时,我无法阻止按钮全屏显示,完全覆盖摄像头预览。我只希望这个按钮大小正常并位于角落,覆盖相机预览,因此用户可以按下它来更改显示为前置或后置摄像头的相机预览。
我已尝试阅读 Layouts documentation、按钮和一些教程,但我的按钮似乎对我更改的任何属性都没有响应。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<foo.bar.ui.camera.CameraSourcePreview
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/switch_camera"
android:src="@drawable/ic_switch_camera_black_48dp"
android:paddingLeft="16dp"
android:paddingBottom="16dp"
android:clickable="true"
android:contentDescription="@string/switch_camera"
android:baselineAlignBottom="false" />
<foo.bar.ui.camera.GraphicOverlay
android:id="@+id/faceOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</foo.bar.ui.camera.CameraSourcePreview>
</LinearLayout>
【问题讨论】:
-
如果你希望它被覆盖,请查看FrameLayout。
-
谢谢,我找到了stackoverflow.com/questions/29072946/…,它帮助我了解了布局中不同组件之间的关系。
-
太棒了,很高兴你知道了。
标签: android android-layout imagebutton android-imagebutton