猿问

带有Google Maps API v2的ViewPager:神秘的黑色视图

我已经将新的Google Maps api v2片段集成到了视图传呼器中。从地图片段滚动时,黑色视图会与相邻片段重叠。有人解决了吗?


public static class PagerAdapter extends FragmentPagerAdapter{


    public PagerAdapter(FragmentManager fm) {

        super(fm);

    }


    @Override

    public int getCount() {

        return NUM_ITEMS;

    }


    @Override

    public Fragment getItem(int position) {


        Fragment pageFragment;


        switch (position) {

        case 0:

            pageFragment = new TabAFragment();

            break;


        case 1:

            pageFragment = new TabBFragment();

            break;


        case 2:

            pageFragment = SupportMapFragment.newInstance();

            break;


        default:

            pageFragment = null;

            break;

        }


        return pageFragment;

    }

}


HUX布斯
浏览 503回答 3
3回答

慕哥6287543

通过在ViewPager内部a的顶部放置另一个具有透明背景的视图,我能够停止过渡后留下的黑色表面FrameLayout:<FrameLayout&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="match_parent" >&nbsp; &nbsp; <android.support.v4.view.ViewPager&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/fragment_container"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent" >&nbsp; &nbsp; </android.support.v4.view.ViewPager>&nbsp; &nbsp; <!-- hack to fix ugly black artefact with maps v2 -->&nbsp; &nbsp; <FrameLayout&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; android:background="@android:color/transparent" /></FrameLayout>

qq_花开花谢_0

SlidingMenu和ViewPager遇到相同的问题。我注意到地图片段中的控件按钮在左侧工件中不是黑色的。我通过覆盖onCreateView()方法解决了问题MapFragment (SupportMapFragment)@Overridepublic View onCreateView(LayoutInflater inflater,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ViewGroup view,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bundle savedInstance) {&nbsp; &nbsp; View layout = super.onCreateView(inflater, view, savedInstance);&nbsp; &nbsp; FrameLayout frameLayout = new FrameLayout(getActivity());&nbsp; &nbsp; frameLayout.setBackgroundColor(&nbsp; &nbsp; &nbsp; &nbsp; getResources().getColor(android.R.color.transparent));&nbsp; &nbsp; ((ViewGroup) layout).addView(frameLayout,&nbsp; &nbsp; &nbsp; &nbsp; new ViewGroup.LayoutParams(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LayoutParams.FILL_PARENT,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LayoutParams.FILL_PARENT&nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; );&nbsp; &nbsp; return layout;}

慕的地10843

Google为此发布了一个修复程序,但仅针对4.1+版本(您无需下载新版本的PlayServices,它们使用了服务器端标志)这就是我用来绕过此问题的方法-确保您不会浪费任何CPU周期大于等于4.1的设备public class FixMapFragment extends SupportMapFragment {&nbsp; &nbsp; @Override&nbsp; &nbsp; public View onCreateView(LayoutInflater inflater,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ViewGroup container,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bundle savedInstanceState) {&nbsp; &nbsp; &nbsp; &nbsp; View view = super.onCreateView(inflater, container, savedInstanceState);&nbsp; &nbsp; &nbsp; &nbsp; // Fix for black background on devices < 4.1&nbsp; &nbsp; &nbsp; &nbsp; if (android.os.Build.VERSION.SDK_INT <&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android.os.Build.VERSION_CODES.JELLY_BEAN) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setMapTransparent((ViewGroup) view);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return view;&nbsp; &nbsp; }&nbsp; &nbsp; private void setMapTransparent(ViewGroup group) {&nbsp; &nbsp; &nbsp; &nbsp; int childCount = group.getChildCount();&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < childCount; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View child = group.getChildAt(i);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (child instanceof ViewGroup) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setMapTransparent((ViewGroup) child);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (child instanceof SurfaceView) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child.setBackgroundColor(0x00000000);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
随时随地看视频慕课网APP

相关分类

Android
我要回答