【发布时间】:2019-08-26 14:07:58
【问题描述】:
我正在尝试使用 ARCore 并显示地图叠加层,使用 MapBox,因为它可以让我自定义设计。我跟着这个答案:https://stackoverflow.com/a/51109938/1298835
问题是地图在覆盖在 ArFragment 上时没有圆角。它看起来像这样:
如果它后面没有 ArFragment,它就可以工作,例如它适用于纯色。使用 ArFragment,您可以看到它正在尝试进行圆角处理,但仍在角落绘制地图。
这是我的 XML 文件:(fragment_maptest.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.google.ar.sceneform.ux.ArFragment"
android:id="@+id/ux_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<!-- CardView for rounded corners -->
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_container"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
card_view:cardCornerRadius="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
tools:ignore="RtlHardcoded">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapbox_cameraTargetLat="40.73581"
app:mapbox_cameraTargetLng="-73.99155"
app:mapbox_cameraZoom="11"/>
</androidx.cardview.widget.CardView>
</RelativeLayout>
还有一个简化的 Kotlin 文件来设置它:(MapTestFragment.kt)
package com.test.test
import android.os.Bundle
import android.view.*
import com.test.test.R
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.Style
class MapTestFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Mapbox.getInstance(this.activity!!, getString(R.string.mapbox_access_token))
return inflater.inflate(R.layout.fragment_maptest, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
// setup map
val mapView = this.activity?.findViewById<MapView>(R.id.mapView)
mapView?.onCreate(savedInstanceState)
mapView?.getMapAsync {
it.setStyle(Style.Builder().fromUri("mapbox://styles/mapbox/streets-v10"))
}
}
}
有没有人遇到并解决过类似的问题,无论是 MapBox 地图在其圆角上绘制,还是类似的圆角视图无法在 ARCore 上运行?
【问题讨论】:
标签: android kotlin mapbox arcore