这是我的布局。 主要思想是ViewPager上面有很少的片段和动作栏。 我成功地添加了一个带有SupportMapFragment的片段。 但是我在android 4.0.4中遇到了一个问题。 当我在下面使用这个布局时,我的地图经常跳过AppBarLayout。当发生跳跃时,我可以在机器人上看到黑色矩形,它的大小在视觉上等于AppBarLayout大小。 每次地图更新都会发生这些跳转(缩放,移动和标记添加/编辑/删除)。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/AppTheme.TabLayout" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
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>
我尝试过的事情:
如果我删除
app:layout_behavior="@string/appbar_scrolling_view_behavior"
然后我的地图填充所有视图空间(预期结果)并且没有跳跃 发生。
但是我想保存CoordinatorLayout的功能,所以第二种方式并不能满足我的所有需求。第一个要求我计算顶部偏移和/或硬编码上边距,我认为不是一个好主意。
我想,问题是,当地图更新时,它放在(0,0)然后 用这个
app:layout_behavior="@string/appbar_scrolling_view_behavior"
移动到正确的位置。但我不太确定。 也许有人已经遇到了这个问题并且可以建议我如何解决地图跳跃问题?