Android 上面有布局层的谷歌地图
我在谷歌地图上面添加了一个布局,我自己的布局有透明的背景。现在,当我添加它时,我无法在我的应用程序中移动谷歌地图,因为上面有一个框架布局。我的要求是,我希望我的谷歌地图能像滑动缩放一样工作,即使上面有一个框架布局 下面是示例代码Android 上面有布局层的谷歌地图,android,google-maps,google-maps-api-2,Android,Google Maps,Google Maps Api 2,我在谷歌地图上面添加了一个布局,我自己的布局有透明的背景。现在,当我添加它时,我无法在我的应用程序中移动谷歌地图,因为上面有一个框架布局。我的要求是,我希望我的谷歌地图能像滑动缩放一样工作,即使上面有一个框架布局 下面是示例代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.googlemapactivity.GoogleMapMainActivity" />
<FrameLayout
android:id="@+id/frameTop"
android:layout_above="@+id/llBottomButtom"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="match_parent"/>
<LinearLayout
android:id="@+id/llBottomButtom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="90">
<Button
android:id="@+id/btnOne"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Route" />
<Button
android:id="@+id/btnTwo"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Current" />
<Button
android:id="@+id/btnThree"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Charge" />
</LinearLayout>
</RelativeLayout>
这里的支持地图片段不会滑动移动或任何东西。有相同的解决方案吗 试试这个:
问题是您试图在id声明上方添加android:layout_=“@+id/llBottomButtom”
行,将其添加到LinearLayout下方,以便对FrameLayout有用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.googlemapactivity.GoogleMapMainActivity" />
<LinearLayout
android:id="@+id/llBottomButtom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="90">
<Button
android:id="@+id/btnOne"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Route" />
<Button
android:id="@+id/btnTwo"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Current" />
<Button
android:id="@+id/btnThree"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Charge" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameTop"
android:layout_above="@+id/llBottomButtom"
android:layout_width="match_parent"
android:descendantFocusability="beforeDescendants"
android:layout_height="wrap_content"/>
因此,我阅读了一些谷歌地图的文档,发现地图提供了cameraAnimation方法,我们可以自己添加滚动,因此我实现了一个GestureDetector.OnEstureListener,其中有两种方法,我按照下面提供的方式使用
override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean {
googMaps?.animateCamera(CameraUpdateFactory.scrollBy(velocityX, velocityY))
return true
}
override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
googMaps?.animateCamera(CameraUpdateFactory.scrollBy(distanceX, distanceY))
return true
}
这就成功了,现在我可以在地图上方使用带有片段的自定义布局,它仍然可以滚动,功能相同。一旦Framelayout将任何片段加载到其容器中,地图停止工作。您能解释一下为什么需要frameTop FrameLayout吗?问题是,我正在添加一个布局,以便在地图上显示一些附加的UI组件,因为我正在添加布局。这是因为您的FrameLayout覆盖了地图片段,我已经尝试了上面的代码。?因为你已经给了FrameLayout匹配父级高度,所以试着包装内容。我得到了答案,添加了它。