Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何显示点击地图上的标记的信息窗口?_Android_Google Maps - Fatal编程技术网

Android 如何显示点击地图上的标记的信息窗口?

Android 如何显示点击地图上的标记的信息窗口?,android,google-maps,Android,Google Maps,当我搜索它时,我发现这些链接是解决方案: 及 但我发现两者都很复杂 我想知道是否有任何简单的方法可以做到这一点。例如,将布局膨胀并在单击的标记上显示为弹出窗口 现在,当用户点击标记时,我只是用一个祝酒词来显示信息。但主要的问题是,我希望这个toast(或其他布局)显示在单击的标记的正上方,而不是默认的toast位置 谢谢请尝试此功能,根据您的要求进行修改: @SuppressWarnings({ "deprecation" }) @Override protected boo

当我搜索它时,我发现这些链接是解决方案:

但我发现两者都很复杂

我想知道是否有任何简单的方法可以做到这一点。例如,将布局膨胀并在单击的标记上显示为弹出窗口

现在,当用户点击标记时,我只是用一个祝酒词来显示信息。但主要的问题是,我希望这个toast(或其他布局)显示在单击的标记的正上方,而不是默认的toast位置


谢谢

请尝试此功能,根据您的要求进行修改:

@SuppressWarnings({ "deprecation" })
    @Override
    protected boolean onTap(int index)
    {
        CustomView customView=new CustomView(MyMap.this);
        absMap.removeAllViews();
        absMap.addView(customView);
        customView.setBackgroundResource(R.drawable.maplocation1);
        customView.setVisibility(View.INVISIBLE);

        customView.removeAllViews();

          absMap.invalidate();
          customView.bringToFront();
          customView.setVisibility(View.VISIBLE);
          TextView tv2=new TextView(MyMap.this);
        //  tv2.setText(overlayItemList.get(index).getTitle());
          tv2.setWidth(170);
          tv2.setSingleLine(true);
          tv2.setEllipsize(TruncateAt.END);
          tv2.setSingleLine(true);
          tv2.setSingleLine();

          tv2.setTextColor(Color.WHITE);
          tv2.setTextSize(14);
          tv2.setTypeface(Typeface.DEFAULT_BOLD);

          TextView tv1=new TextView(MyMap.this);
          tv1.setSingleLine();
          tv1.setWidth(170);
          tv1.setSingleLine(true);
          tv1.setEllipsize(TruncateAt.END);
          tv1.setSingleLine(true);
          tv2.setText(overlayItemList.get(index).getSnippet());


          tv1.setTextColor(Color.WHITE);
          tv1.setTextSize(12);
          tv1.setTypeface(Typeface.DEFAULT_BOLD);
          customView.setTag(overlayItemList.get(index).getTitle());
          customView.addView(tv2, new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,10,5));
          customView.addView(tv1, new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,10,25));
          customView.setLayoutParams(new MapView.LayoutParams( 250, 100, overlayItemList.get(index).getPoint(),-125,-137, MapView.LayoutParams.MODE_MAP|MapView.LayoutParams.TOP_LEFT));
          customView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) 
            {
            }
        });


    }

嘿,获取触摸点的X和Y坐标,并在那里显示自定义样式的弹出窗口……。您可以使用
AlertDialog
它很简单,您可以在其中膨胀任何布局。但它会填满整个屏幕。@VipinSahu,我首先想到的。但是我不知道我是否可以写一个代码来表示“这个特定的观点必须出现在这个特定的屏幕上”@vtuhtan这就是问题所在。如果我在整个屏幕上显示某个内容(非活动背景),这是一个主要的用户体验问题在webview上设置一个OnTouchListener,找到接触点X和Y坐标,然后使用hanlder将视图添加到地图视图,或者显示一个弹出窗口。此代码称为ontap of marker。customView是一个customView类,它扩展了绝对布局,已经在代码中的任何地方编写。我们只需要制作这个类的一个对象&在x,y位置上使用它。