【问题标题】:How to show pop up on clicking map overlay?单击地图叠加层时如何显示弹出窗口?
【发布时间】:2010-03-04 13:41:21
【问题描述】:

我想在单击我已添加到 android 中的谷歌地图的地图叠加层时显示一个包含一些数据的自定义图像。

谁能指导我如何创建自定义图像或东西以显示在谷歌地图上并带有一些数据?

有人告诉我去自定义视图,但我不知道。

【问题讨论】:

  • 我不完全明白你想做什么。您可以将 onclicklistener 注册到地图叠加层上的某个点,然后在 toast 消息中显示。您也可以将图像添加到 toast 消息中。如果您稍微说明您的问题,我可以举一些例子。

标签: android google-maps


【解决方案1】:

This project 演示了在地图顶部添加弹出面板(与Toast 不同的是持久面板)。

【讨论】:

    【解决方案2】:

    要创建显示图像和一些文本的自定义 toast 消息,请使用此 java 代码。

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));
    
    TextView text = (TextView) layout.findViewById(R.id.text);
    
    text.setText(content);
    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageBitmap(bmImg);
    
    
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
    

    还有这个布局文件

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              android:background="#DAAA"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="40dp"
               android:layout_height="40dp"
               android:layout_marginRight="10dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
    </LinearLayout>
    

    【讨论】:

    • 是的,这很有帮助,但我可以在屏幕上显示一些东西而不是吐司。吐司出现然后消失。图像以烤面包的形式出现,但图像的形状却不是烤面包。
    • 添加另一个视图(我是文本或图像视图)。当您点击时,您可以为此设置Visibility()。更多信息:developer.android.com/resources/samples/ApiDemos/src/com/…
    • 在“setImageBitmap”之前修复了初始化图像的代码。请确认。
    猜你喜欢
    • 2015-06-27
    • 2021-04-26
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多