0

在 Xamarin 中,如何让自动链接与 Google Map InfoWindow 中显示的一些 TextView 一起使用。

这是我的 custom_info_window XML 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/Phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:autoLink="phone"/>

    <TextView
        android:id="@+id/Web"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:autoLink="web"/>

</LinearLayout>

这是我的 InfoWindow 类:

public class InfoWindow : Java.Lang.Object, GoogleMap.IInfoWindowAdapter
{
    public View GetInfoContents(Marker p0)
    {
        var inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;

        View v = inflater.Inflate(Resource.Layout.custom_info_window, null);

        TextView title = (TextView) v.FindViewById(Resource.Id.Phone);
        title.Text = "Phone number: 0800 32 32 32";

        TextView description = (TextView) v.FindViewById(Resource.Id.Web);
        description.Text = "Email address: me@me.com";

        return v;
    }

    public View GetInfoWindow(Marker p0)
    {
        return null;
    }
}

当我单击标记时,我会显示 InfoWindow,并且它的格式正确,如 InfoWindow 类中的编码。

但是,当我单击任一自动链接项目时,自动链接不起作用。InfoWindow 上的单击仅注册为整个 InfoWindow 单击,并且不会分成两个不同的 TextView。

我可以帮忙吗?

提前致谢

4

3 回答 3

0

出于一个简单的原因,您无法获得任何帮助来实现您想要实现的目标。您在 中看到的InfoWindow不是您定义的布局,而是从中绘制的图像。意思是你试图用它做的事情InfoWindow是不可能的。

来自谷歌的文档:

注意:绘制的信息窗口不是实时视图。视图在返回时呈现为图像(使用View.draw(Canvas))。这意味着对视图的任何后续更改都不会反映在地图上的信息窗口中。要稍后更新信息窗口(例如,加载图像后),请调用showInfoWindow(). 此外,信息窗口不会尊重任何普通视图的典型交互性,例如触摸或手势事件。但是,您可以在整个信息窗口上收听通用单击事件,如下节所述。

于 2014-02-20T08:53:02.497 回答
0

在xml中试试这个

android:linksClickable="true"

于 2014-04-07T18:44:19.557 回答
0

你不能不使用一些肮脏的技巧。

InfoWindow 不是实时视图,它只是从您提供的视图生成的图像。所以任何事件都不会被触发。

但是,如果您真的需要这样做,这是最好的方法:Google Maps Android API v2 - Interactive InfoWindow(就像在原始的 android google maps 中一样) 我自己使用它,它很棒(而且我正在使用 Xamarin)。

例子 :

这是 MapWrapper:http ://pastebin.com/CDfxVZvi

这是适配器: http: //pastebin.com/rHsjxxyn

这是触摸监听器:http: //pastebin.com/4kMTygfE

然后我创建我需要的一切:http: //pastebin.com/AGyRTnu4

它比 Java 复杂一点,因为我们必须在构造函数中传递每个对象。不要忘记在布局中的地图容器周围放置一个 MapWrapper。

于 2014-02-20T08:49:03.793 回答