首页 > 解决方案 > 在谷歌地图中实现 UI 组件,如 imageviews、recyclerviews安卓中的标签

问题描述

我正在实施谷歌地图,我想改变我的 xml 代码

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_10sdp"
            android:layout_marginRight="@dimen/_10sdp"
            android:gravity="center"
            android:orientation="horizontal">

        <ImageView
            android:id="@+id/MapCenter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/rvMap"
            android:layout_centerInParent="true"
            android:src="@drawable/map_center" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvMap"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/_40sdp" />
    </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_10sdp"
            android:layout_marginRight="@dimen/_10sdp"
            android:gravity="center"
            android:orientation="horizontal">

        <ImageView
            android:id="@+id/MapCenter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/rvMap"
            android:layout_centerInParent="true"
            android:src="@drawable/map_center" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvMap"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/_40sdp" />
    </fragment>

当我更改为 Fragment 时,它没有正确显示内部组件,请告诉我如何在 Fragment 中使用 Ui 组件。

标签: androidxmlgoogle-mapsandroid-layoutfragment

解决方案


您的 LinearLayout 小部件未关闭,请执行此操作

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_10sdp"
            android:layout_marginRight="@dimen/_10sdp"
            android:gravity="center"
            android:orientation="horizontal">

        <ImageView
            android:id="@+id/MapCenter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/rvMap"
            android:layout_centerInParent="true"
            android:src="@drawable/map_center" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvMap"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/_40sdp" />
    </LinearLayout>

推荐阅读