将小部件放在彼此的顶部

时间:2022-10-01 11:59:03

I have a camera widget which would be a "background", on top of it I would like to have an image and a button. What layout should I use to correctly place image and button on top of camera widget?

我有一个相机小部件,它将是一个“背景”,在它的顶部,我想有一个图像和一个按钮。我应该使用什么布局将图像和按钮正确放置在相机小部件的顶部?

The following layout pushes camera widget off the screen (just image and button are visible):

以下布局将相机小部件推离屏幕(只显示图像和按钮):

<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>

3 个解决方案

#1


2  

Use RelativeLayout - it uses the order of definition of its children for their Z-order (on top of each other). Firs declare your CAMView and then (as siblings in the resource file) - the button and the image view. Of course you should consider their relative position on the screen (inside their parent), but in short - each next child is drawn "on top" of the previous if they overlap in x,y coordinates.

使用RelativeLayout - 它使用其子项的定义顺序作为其Z顺序(在彼此之上)。 Firs声明你的CAMView然后(作为资源文件中的兄弟姐妹) - 按钮和图像视图。当然你应该考虑它们在屏幕上的相对位置(在它们的父母内部),但简而言之 - 如果它们在x,y坐标中重叠,则每个下一个孩子都被绘制在前一个上面。

In your case:

在你的情况下:

<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>

Use the android:layout_alignParent... properties to place your items inside their parent

使用android:layout_alignParent ...属性将项目放在其父项中

#2


0  

In case you want to give alignment to any of the child views eg button should be on top and in middle then its better to go for RelativeLayout

如果您想要对齐任何子视图,例如按钮应位于顶部和中间,那么最好去RelativeLayout

#3


-2  

If you use a constraint layout, the widgets that are below in the list will appear all the others in the app.See this image

如果使用约束布局,则列表中下方的窗口小部件将显示在应用程序中的所有其他窗口小部件中。查看此图像

将小部件放在彼此的顶部

#1


2  

Use RelativeLayout - it uses the order of definition of its children for their Z-order (on top of each other). Firs declare your CAMView and then (as siblings in the resource file) - the button and the image view. Of course you should consider their relative position on the screen (inside their parent), but in short - each next child is drawn "on top" of the previous if they overlap in x,y coordinates.

使用RelativeLayout - 它使用其子项的定义顺序作为其Z顺序(在彼此之上)。 Firs声明你的CAMView然后(作为资源文件中的兄弟姐妹) - 按钮和图像视图。当然你应该考虑它们在屏幕上的相对位置(在它们的父母内部),但简而言之 - 如果它们在x,y坐标中重叠,则每个下一个孩子都被绘制在前一个上面。

In your case:

在你的情况下:

<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>

Use the android:layout_alignParent... properties to place your items inside their parent

使用android:layout_alignParent ...属性将项目放在其父项中

#2


0  

In case you want to give alignment to any of the child views eg button should be on top and in middle then its better to go for RelativeLayout

如果您想要对齐任何子视图,例如按钮应位于顶部和中间,那么最好去RelativeLayout

#3


-2  

If you use a constraint layout, the widgets that are below in the list will appear all the others in the app.See this image

如果使用约束布局,则列表中下方的窗口小部件将显示在应用程序中的所有其他窗口小部件中。查看此图像

将小部件放在彼此的顶部