在SupportMapFragment上显示/隐藏工具栏

时间:2016-08-17 01:38:01

标签: android google-maps android-toolbar supportmapfragment

我的应用程序使用SupportMapFragment并且工作正常。

但如何使用工具栏实现Layout ScrollFlags?使用RecyclerView和ViewPager的其他片段按预期工作。

screenshot here

这里有一些代码

toolbar.xml

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:theme="@style/AppTheme.AppBarOverlay"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/textView_title"
        android:textColor="@android:color/white"
        android:textSize="20sp"
        android:text="@string/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</android.support.v7.widget.Toolbar>

layout activity.xml

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.yoesuv.infomadiun.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/toolbar_top" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

这是SupportMapFragment的一部分

public class MapsFragment extends SupportMapFragment implements OnMapReadyCallback,
        GoogleMap.OnMyLocationButtonClickListener{

    private CoordinatorLayout cLayout;
    private Snackbar snackbar;

    private int mapType;
    private boolean moveCamera;
    private GoogleMap gMap;

    public static MapsFragment getInstance() {
        return new MapsFragment();
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        cLayout = (CoordinatorLayout) getActivity().findViewById(R.id.coordinator_layout);

        setHasOptionsMenu(true);
        getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        gMap = googleMap;
        mapType = 1;
        moveCamera = true;
        if(MapsFragment.this.isVisible()) {
            loadMap(googleMap, mapType);
        }
    }

    private void loadMap(final GoogleMap googleMap, int type){
        /* code for load map */
        /* works as expected */
    }
}

0 个答案:

没有答案