gpt4 book ai didi

android - 添加十字准线覆盖到谷歌地图 v2

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:11:04 25 4
gpt4 key购买 nike

我正在尝试向固定在屏幕中央的谷歌地图添加叠加层,以便用户可以使用它来精确选择位置。

目前下面的代码绘制了一个带有居中十字准线图像的 map View ,但是当按钮位于 map View 下方时, map 的中心发生了变化,十字准线不再代表 map 的中心点,该中心点已向上移动了高度按钮。

我看过Android - Showing a crosshair in the center of my Google Map但它似乎只适用于 v1 :(

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/locationpicker_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/locationpicker_add_venue"
android:clickable="true"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crosshairs"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/locationpicker_add_venue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text = "Add new venue here"
android:layout_alignParentBottom="true"/>
</RelativeLayout>

最佳答案

为了实现这种效果,我使用了一个围绕 map fragment 的相对布局, ImageView 居中。有关示例,请参见下文;

Crosshair centered on android google map

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/locationpicker_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/crosshairs"
android:layout_gravity="center_vertical"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/locationpicker_add_venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "Add new venue here"
style="@style/Buttonpurple_style"
android:layout_gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

关于android - 添加十字准线覆盖到谷歌地图 v2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15369261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com