我在地图框上有一个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。