将 imageView 添加到 coordinatorLayout

Add imageView to coordinatorLayout

这是我的协调器布局。一切正常,我都能看到。

但是我看不到 ImageView。在代码中,我正在正确初始化 ImageView 并有一个对象。我需要屏幕中央的图像视图。

如果我将 ImageView 更改为按钮,我会在屏幕中央看到按钮,但如果我更改为其他内容,我将看不到该元素。

请问如何将 ImageView 添加到 coordinatorLayout?

此代码在 coordinatorlayout 中。

谢谢。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<ImageView
    android:id="@+id/status_btn"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_gravity="center"
    android:background="@color/red" />

<Button
    android:id="@+id/delete_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Smazat"
    android:visibility="gone" />

<include
    layout="@layout/panel_camera_preview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<!--height a width se nastavuje dynamicky-->
<LinearLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:clipToPadding="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <RelativeLayout
        android:id="@+id/bottom_sheet_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/header_vg"
            android:layout_width="match_parent"
            android:layout_height="@dimen/vision_bottom_sheet_header_height"
            android:layout_alignParentTop="true"
            android:background="@color/gray_header_vision"
            android:gravity="center">

            <TextView
                android:id="@+id/header_tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:textColor="@color/white"
                android:textSize="16sp" />

        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/vision_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/header_vg"
            android:background="@color/white"
            android:scrollbars="vertical"
            android:visibility="gone" />

        <include
            android:id="@+id/empty_vg"
            layout="@layout/panel_vision_tutorial"
            android:layout_width="match_parent"
            android:layout_height="@dimen/vision_bottom_sheet_item_height"
            android:layout_below="@+id/header_vg" />

    </RelativeLayout>

</LinearLayout>

</android.support.design.widget.CoordinatorLayout>

这是我的 panel_camera_preview:

<my_package.CameraSourcePreview
android:id="@+id/camera_preview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray">

<my_package.GraphicOverlay
    android:id="@+id/face_overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</my_package.CameraSourcePreview>

CoordinatorLayout 是一个FrameLayout,因此最后一个View 按顺序覆盖前面的View。然后 Imageview 结果不可见,因为它被您的 panel_camera_preview 覆盖,而 Button 结果可见,但前提是 运行 在 Lollipop 或更高版本上,导致其默认高度(2dp).