【问题标题】:Rounded corners for MapBox overlay over ARCore ArFragmentARCore ArFragment 上 MapBox 覆盖的圆角
【发布时间】: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


    【解决方案1】:

    我想通了!

    您需要做的就是启用textureMode。这有效:

    <!-- 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"
                app:mapbox_renderTextureMode="true"/>
    </androidx.cardview.widget.CardView>
    

    【讨论】:

      【解决方案2】:

      我没有使用 ARCore 库,但 AR 视图很可能适用于软件层。而cardview,为了创建一个圆形,使用了需要硬件加速的轮廓裁剪

      【讨论】:

      • 嗯,我不确定。奇怪的是,用其他东西(例如简单的 TextView)替换 MapView 会使圆角起作用。
      • 您确定在 cardview 中使用其他类型的视图可以进行舍入吗?你目测确认了吗?
      • 是的。我只是仔细检查了一下,它甚至可以与谷歌地图片段一起使用。唉,我的任务是使用带有自定义样式的 MapBox,所以希望有办法
      • 这可以代替 &lt;fragment android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent"/&gt;
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多