MapBox 覆盖在 ARCore ArFragment 上的圆角

Rounded corners for MapBox overlay over ARCore ArFragment

我正在尝试使用 ARCore 并显示地图叠加层,使用 MapBox because it lets me customize the design. I followed this answer:

问题是当覆盖在 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 上不起作用?

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

我想通了!

您只需启用 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>