【发布时间】:2020-09-04 17:11:19
【问题描述】:
我在地图片段上有一个 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 设置为 image 并且我可以单击它。看起来 ImageView 在那里,在地图片段的顶部,但我看不到它。
如何将地图片段发送到后面或将视图带到前面?
【问题讨论】:
-
将片段 layout_height 更改为固定大小,例如:80 dp 覆盖整个屏幕,因此您看不到 imageView
-
您是否尝试设置
android:elevation="2dp"而不是android:translationZ? -
@mohosyny; imageView 必须在 mapview 上。并且地图视图必须覆盖所有屏幕。
-
@ReazMurshed;是的,我尝试了海拔。不工作:(
-
@ReazMurshed;我尝试添加另一个具有相同可绘制对象的图像视图,你是对的。我看不到:(
标签: android android-constraintlayout supportmapfragment