我想向我的谷歌地图应用程序添加一个像下面的谷歌地图标准按钮一样的按钮。请看下图。第一个按钮是谷歌地图标准按钮之一,第二个按钮是用户自己添加的另一个自定义按钮。
在下面的链接中,@chintan khetiya 描述了如何从布局代码向 map 添加按钮,但这不是像标准按钮那样的按钮。
How to draw free hand polygon in Google map V2 in Android?
这是@chintan khetiya 的代码:
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<FrameLayout
android:id="@+id/fram_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/btn_draw_State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Free Draw" />
</FrameLayout>
为了创建像下图中的按钮一样的按钮,最好的方法是什么?当然,该位置必须正好位于标准按钮下方,并且图像应该保留其声音。 我们是否需要使用上面的布局代码并从布局中手动更改图像和位置,还是有更好的方法?我认为谷歌应该创建另一种方式将此类按钮添加到mao中。有这样的方法吗?
最后,我更喜欢以编程方式添加此按钮,而不是将其添加到布局上。
谢谢
最佳答案
我做了很多研究,也阅读了谷歌开发者文档。谷歌似乎没有引入添加这些按钮的标准方法。唯一的方法是使用自定义布局和代码添加它们。
最后,我对问题中引入的布局代码进行了一些更改,并在我的代码中使用它。感谢@chintan khetiya感谢他在 How to draw free hand polygon in Google map V2 in Android? 中的良好回答
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<FrameLayout
android:id="@+id/fram_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/btn_draw_State"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right|top"
android:layout_marginTop="55dp"
android:layout_marginRight="11dp" />
</FrameLayout>
我们应该注意到的要点是,按钮似乎是 40dp
和 11dp
margin
从 right
关于android - 如何在谷歌地图v2 android上添加像标准 map 按钮一样的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21402636/