MapFragment causes flickering in ViewPager

会有一股神秘感。 提交于 2019-12-12 09:24:04

问题


I use a (Support)MapFragment inside a (Support)ViewPager, filled by a FragmentPagerAdapter.

The ViewPager consists of three fragments, with the map fragment on the right: |x|x|map|. When I swipe to the right from the first fragment, die whole UI visibly redraws as the MapFragment is loaded and the screen flickers. Once the map is loaded for the first time swiping between screens works fine.

How can I fix this?


回答1:


I had the same issue with my project's (rather complex) structure: HostActivity -> HostFragment with ViewPager -> ListView with embedded MapFragment.

I tried to solve this issue following this gmaps-api-issues thread but with no luck (though I recommend reading it as it provides some background on the issue itself).

Then I stumbled upon this blog post and it did the trick for me:

public void onCreate(Bundle savedInstanceState) {
    ...
    ViewPager pager = (ViewPager)findViewById(R.id.pager);
    ...
    pager.setAdapter(adapter);
    pager.requestTransparentRegion(pager); // This line solved the problem for me
    ...
}


来源:https://stackoverflow.com/questions/16739804/mapfragment-causes-flickering-in-viewpager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!