Android GMaps v2处理方向更改

时间:2016-04-15 09:52:27

标签: java android google-maps android-fragments

使用谷歌地图片段处理方向更改时遇到了麻烦。 问题是当我使用这些线来防止地图重新加载时方向改变,我没有加载我的土地布局,当我改变方向后,它抛出

  

二进制XML文件行#19:错误膨胀类片段

这是清单代码,我发现它可以阻止地图重新加载。如果我将忽略这些行,我的应用程序将处理方向更改,但每次更改方向时都会重新加载地图。

 android:configChanges="orientation|uiMode|screenSize|fontScale"
 android:screenOrientation="user"

这是我的片段

    public class BlankFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.activity_main_screen_map, container, false);
    }
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        LayoutInflater inflater = LayoutInflater.from(getActivity());
        populateViewForOrientation(inflater, (ViewGroup) getView());
    }

    private void populateViewForOrientation(LayoutInflater inflater, ViewGroup viewGroup) {
        viewGroup.removeAllViewsInLayout();
        View subview = inflater.inflate(R.layout.activity_main_screen_map, viewGroup);

    }
}

这是我的活动

    public class MainScreenMapActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainshit);
      BlankFragment frag= new BlankFragment();
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .add(R.id.container, frag)
                .addToBackStack("myStack")
                .commit();
    }
}

我的端口布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#33ffffff"
    android:elevation="0dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#33ffffff"
        android:elevation="0dp"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

</android.support.design.widget.AppBarLayout>
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_alignParentTop="true" />

我的土地布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#33ffffff"
    android:elevation="0dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_alignParentLeft="true">
    <android.support.v7.widget.Toolbar
        android:layout_width="?attr/actionBarSize"
        android:layout_height="match_parent"
        android:background="#33ffffff"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

</android.support.design.widget.AppBarLayout>
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_alignParentTop="true" />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

0 个答案:

没有答案