使用谷歌地图显示叠加Recyclerview

时间:2018-04-24 07:49:30

标签: java android android-layout android-recyclerview overlay

您好我正在尝试创建一个必须显示地图的应用程序,所以在我的片段中我已经在我的片段中成功实现了mapview但是我不知道如何在地图上实现overlay recyclerview可以在image看到所以任何帮助,我也在谷歌搜索,但没有得到任何适当的解决方案 这是我的地图代码

public class NearbyFragment extends Fragment {

    MapView mMapView;
    private GoogleMap googleMap;
    public NearbyFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =  inflater.inflate(R.layout.fragment_nearby, container, false);
        mMapView = (MapView) view.findViewById(R.id.mapview);
        mMapView.onCreate(savedInstanceState);

        mMapView.onResume();

        try{
            MapsInitializer.initialize(getActivity().getApplicationContext());
        }
        catch (Exception e){
            e.printStackTrace();
        }
        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                googleMap = googleMap;

                // For showing a move to my location button
                googleMap.setMyLocationEnabled(true);

                // For dropping a marker at a point on the Map
                LatLng sydney = new LatLng(-34, 151);
                googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker Title").snippet("Marker Description"));

                // For zooming automatically to the location of the marker
                CameraPosition cameraPosition = new CameraPosition.Builder().target(sydney).zoom(12).build();
                googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
            }
        });
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        mMapView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mMapView.onLowMemory();
    }
}

1 个答案:

答案 0 :(得分:0)

使用RelativeLayout安排相对的内容,以便将RecyclerView置于MapView之上 它看起来像这样:

<RelativeLayout
android:layout_height="match-parent"
android:layout_width="match-parent">

    <MapView
    android:layout_height="match-parent"
    android:layout_width="match-parent"/>

    <RecyclerView
    android:layout_alignParentBottom="true"
    android:layout_height="wrap-content"
    android:layout_width="match-parent"/>

</RelativeLayout>

只是把它写在我的头顶,所以请原谅我,如果它不是100%语法正确。在