【问题标题】:SupportMapFragment in Nexus OneNexus One 中的 SupportMapFragment
【发布时间】:2013-01-23 17:56:18
【问题描述】:

我在将旧的 Google Nexus One 与新的 SupportMapFragment 混合时遇到了一些问题。

在特定的横向视图中,我有一个HorizontalScrollView,其中有一个地图一些信息,您必须按顺序滚动实际查看信息。

问题是滚动使(不知何故我现在无法理解)SupportMapFragment 的背景可见(默认情况下似乎是黑色),而实际上滚动整个视图

图片说明我的意思。

虽然不是完全相同的问题,但在gmaps-api-issues 中有一个类似的报告错误,关于它


所以,到目前为止我已经测试过:

  • 将背景设置为 @color/transparent,即使在 XML 中和/或以编程方式。
  • 更改SupportMapFragment z 排序

在调用我的地图之前设置此代码:

GoogleMapOptions op = new GoogleMapOptions();
op.zOrderOnTop(true);
SupportMapFragment.newInstance(op);

所以我没有主意了。 我已经成功地测试了相同的代码:

  • Galaxy Nexus
  • HTC Desire HD
  • Samsung Galaxy S3
  • Samsung Galaxy Mini
  • Galaxy Ace

编辑:有趣的是,截屏让我意识到捕捉我的具体案例是不可能的。截屏时,只有再次切换到纵向和横向才能重现错误。

有什么想法吗?我错过了什么明显的东西吗?

提前感谢您的 cmets。

【问题讨论】:

  • 这个post 听起来很相似,所以可能会有所帮助

标签: android google-maps-android-api-2 nexus-one supportmapfragment


【解决方案1】:

我有一个 very similar issue,但是当我添加 SlidingMenu library 时,我使用 hack on this comment 修复了它

public class MyMapFragment extends SupportMapFragment() {

   @Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View view = super.onCreateView(inflater, container, savedInstanceState);
       setMapTransparent((ViewGroup) view);
       return view;
   };

   private void setMapTransparent(ViewGroup group) {
       int childCount = group.getChildCount();
       for (int i = 0; i < childCount; i++) {
       View child = group.getChildAt(i);
       if (child instanceof ViewGroup) {
           setMapTransparent((ViewGroup) child);
       } else if (child instanceof SurfaceView) {
           child.setBackgroundColor(0x00000000);
       }
   }
 }

【讨论】:

    【解决方案2】:

    只是为了补充 Robert Estivill 的答案 - 最好不要在 >= 4.1 的设备上运行代码,因为它们没有问题。

    稍作修改的版本:

    public class FixMapFragment extends SupportMapFragment {
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = super.onCreateView(inflater, container, savedInstanceState);
    
            // Fix for black background on devices < 4.1
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN){
                setMapTransparent((ViewGroup) view);
            } 
            return view;
        }
    
        private void setMapTransparent(ViewGroup group) {
            int childCount = group.getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = group.getChildAt(i);
                if (child instanceof ViewGroup) {
                    setMapTransparent((ViewGroup) child);
                } else if (child instanceof SurfaceView) {
                    child.setBackgroundColor(0x00000000);
                }
            }
        }
    }
    

    我会将此放在评论中,但我没有足够的代表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2012-09-29
      相关资源
      最近更新 更多