【问题标题】:Autolink TextViews in Google Map InfoWindowGoogle Map InfoWindow 中的自动链接文本视图
【发布时间】:2014-02-20 08:43:09
【问题描述】:

在 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。

我可以帮忙吗?

提前致谢

【问题讨论】:

    标签: android textview xamarin infowindow autolink


    【解决方案1】:

    出于一个简单的原因,您无法获得任何帮助来实现您想要实现的目标。您在InfoWindow 中看到的不是您定义的布局,而是从中绘制的图像。这意味着您无法使用InfoWindow 进行操作。

    来自 Google 的文档:

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

    【讨论】:

      【解决方案2】:

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

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

      但是,如果你真的需要这样做,这是最好的方法:Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps) 我自己使用它,它很棒(我正在使用 Xamarin)。

      例子:

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

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

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

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

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

      【讨论】:

      • Stephane,我看到该链接没有使用 Xamarin。您能否帮助我编写代码以使其在 Xamarin 中运行?这会节省我很多时间。也许只是一些简单的代码示例。
      • 我已经添加了代码。花了我大约一天的时间,所以在做一些其他事情时玩得开心;)
      • Stephane,我在将所有代码捆绑在一起时遇到了一些麻烦。您是否有一个简单的 Xamarin 项目,其中只有我可以查看的相关代码?我将不胜感激:)
      【解决方案3】:

      在 xml 中试试这个

      android:linksClickable="true"

      【讨论】:

        猜你喜欢
        • 2021-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-26
        • 1970-01-01
        • 1970-01-01
        • 2013-02-17
        相关资源
        最近更新 更多