2010-03-04 87 views
7

我想显示一个自定义图像,其中包含一些数据,同时单击我已添加到谷歌地图在Android中的地图叠加。如何在点击地图叠加层上显示弹出窗口?

任何人都可以指导我如何创建自定义图像或东西要显示在谷歌地图上的一些数据呢?有些人告诉我去自定义的视图,但我不知道他们。

+0

我不完全明白你想要做什么。您可以将onclicklistener注册到地图覆盖图上的某个点,然后显示在Toast消息中。您也可以将图像添加到Toast消息中。 如果你指出你的问题,我可以举一些例子。 – Janusz 2010-03-04 14:05:54

回答

3

要创建显示图像和一些文本的自定义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> 
+0

是的,这是有帮助的,而不是敬酒,我可以展示一些东西留在屏幕上。出现然后消失。图像来烤面包而不是烤面包形状的图像。 – UMAR 2010-03-05 07:42:37

+0

添加另一个视图(它是我的文本或图像视图)。当你点击,你可以setVisibility()。更多:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Visibility1.html – Praveen 2010-03-09 16:39:12

+0

只需修复代码以在“setImageBitmap”之前初始化图像。请确认。 – Siddharth 2012-12-13 03:16:12

相关问题