即使我将父母布局更改为相对布局,我的ImageView也不会显示在前面。
我想这是我所不知道的最小错误。
例如:
有一个片段(地图),一个按钮和此地图的图例。
按钮通常在运行时显示,但图例不会显示。
有关更多信息,这是xml代码。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="8dp" />
<Button
android:id="@+id/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="16dp"
android:layout_marginEnd="13dp"
android:backgroundTint="@color/colorAccent"
android:text="select"
android:textColor="@color/colorPrimary" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:adjustViewBounds="true"
android:contentDescription="legend"
android:translationZ="1000dp"
app:srcCompat="@drawable/legend_imageview" />
答案 0 :(得分:0)
好的,这就是答案。
很简单。
app:srcCompat="@drawable/legend_imageview"
必须更改为
android:src="@drawable/legend_imageview"
答案 1 :(得分:0)
使用此代码进行布局
将相对布局更改为框架布局
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<Button
android:id="@+id/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="16dp"
android:layout_marginEnd="13dp"
android:backgroundTint="@color/colorAccent"
android:text="select"
android:textColor="@color/colorPrimary" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:adjustViewBounds="true"
android:contentDescription="legend"
app:srcCompat="@drawable/legend_imageview" />