translationZ 在我的 ConstraintLayout 中无法使用地图片段

translationZ not working in my ConstraintLayout with map fragment

我在 Map frangment 上有一个 ImageView,它们都放在了 ConstraintLayout 中。我为 ImageView 设置 android:translationZ="2dp" 然后 android:elevation="2dp" 但仍然看不到图像。

map_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/mapView"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context=".MapsActivity" />

    <ImageView
        android:id="@+id/testImage"
        android:layout_width="64dp"
        android:layout_height="64dp"
        app:layout_constraintBottom_toBottomOf="@+id/mapView"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/test"
        android:translationZ="2dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

奇怪的是,我为图像设置了一个 OnClickListener,我可以点击它。看起来 ImageView 在那里,在地图片段的顶部,但我看不到它。

如何将地图片段发送到后面或将视图置于前面?

app:srcCompat 更改为 android:src 效果很好。最终 xml 看起来像:

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/mapView"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context=".MapsActivity" />

    <ImageView
        android:id="@+id/testImage"
        android:layout_width="64dp"
        android:layout_height="64dp"
        app:layout_constraintBottom_toBottomOf="@+id/mapView"
        app:layout_constraintStart_toStartOf="parent"
        android:src="@drawable/test"
        android:translationZ="2dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

感谢@mohosyny 和@ReazMurshed。