Android 将小部件放在彼此的顶部
我有一个相机小部件,这将是一个背景,在它上面我想有一个图像和一个按钮。我应该使用什么布局来正确地将图像和按钮放置在相机小部件的顶部 以下布局将摄像头小部件从屏幕上推出,只有图像和按钮可见:Android 将小部件放在彼此的顶部,android,layout,Android,Layout,我有一个相机小部件,这将是一个背景,在它上面我想有一个图像和一个按钮。我应该使用什么布局来正确地将图像和按钮放置在相机小部件的顶部 以下布局将摄像头小部件从屏幕上推出,只有图像和按钮可见: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<eu.livotov.labs.android.camview.CAMView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/zxScanCamera"/>
<ImageView
android:src="@drawable/hud"
android:scaleType="centerInside"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
style="@style/StdText"
android:id="@+id/flashLight"
android:layout_width="match_parent"
android:text="@string/scan_flash_on"
android:background="?android:attr/selectableItemBackground"/>
</FrameLayout>
如果您想对齐任何子视图,例如按钮应位于顶部和中间,那么最好选择RelativeLayout使用-它使用其子视图的定义顺序作为它们的Z顺序。首先声明您的CAMView,然后在资源文件(按钮和图像视图)中声明为同级。当然,你应该考虑他们在父母的屏幕上的相对位置,但简而言之,如果在X、Y坐标上重叠,每个下一个孩子都被画在前面。 就你而言:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<eu.livotov.labs.android.camview.CAMView
android:layout_height="match_parent"
android:layout_width="match_parent"
.../>
<ImageView
...
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<Button
...
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
使用android:layout\u alignParent。。。属性将您的项目放置在其父项中如果使用约束布局,则列表中下面的小部件将显示在应用程序中所有其他小部件的上方。例如,在此情况下,图像视图1将显示在图像视图2的顶部。从上方或上方,我的意思是朝向用户或朝向屏幕外。imageView1将显示在imageView2上方,就像您将一张纸放在一张大纸上一样
FrameLayout是正确的选择。尝试将ImageView的背景设置为透明android:background=@android:color/transparentThanks,透明背景不起作用,但我使用了一些选项,设置android:background=@drawable/hud+android:layout_gravity=center确实解决了我的问题。