【问题标题】:Add imageView to coordinatorLayout将 imageView 添加到 coordinatorLayout
【发布时间】:2016-06-28 11:47:28
【问题描述】:

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

但我看不到 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。
  • 抱歉,我编辑了我的问题。我需要屏幕中心的图像视图。如果我将 ImageView 更改为按钮,我会在屏幕中心看到按钮,但如果我更改为其他内容,我将看不到该元素。 @Drv
  • 提供你的panel_camera_preview布局..!!

标签: android layout imageview android-coordinatorlayout


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多