【问题标题】:Rounded corner mapbox mapView圆角mapbox mapView
【发布时间】:2018-06-21 16:26:32
【问题描述】:

所以我正在尝试使用 mapbox mapView 将小型迷你地图添加到我的 android 应用程序中。我正在尝试为其添加圆角,但我似乎无法找到一种方法来做到这一点。有没有好的方法来做到这一点?我知道一种选择是使用 CardView,但它似乎没有绕过地图的角落。

【问题讨论】:

  • 为此使用任何库。
  • 是的,你可以这样做。关注this 回答。它会帮助你做到这一点。
  • 我不完全理解这种方法。我试图按照答案所说的去做,但是 mapbox mapview 没有调整大小。这可能是 mapbox 的问题吗?

标签: java android mapbox cardview


【解决方案1】:
<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="400dp"
    app:cardCornerRadius="12dp"
    app:cardElevation="12dp">

    Put your mapview in here

</android.support.v7.widget.CardView>

这张卡应该很适合你。

【讨论】:

  • 我已经尝试过这样做,但我的地图视图似乎仍然保持方形,因为它实际上适合角落。 mapbox mapView 是不是很奇怪?
【解决方案2】:

这是 Mapbox 与背景中的 AR 视图相结合的问题。对我有用的是在地图中启用renderTextureMode

试试这个:

<!-- 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>

【讨论】:

    【解决方案3】:

    您的 Mapbox 地图在 XML 中的布局宽度和高度是多少?

    我关注了https://developer.android.com/guide/topics/ui/layout/cardview,这个 XML 对我有用

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:layout_marginTop="32dp"
        card_view:cardCornerRadius="10dp"
        card_view:layout_constraintEnd_toEndOf="parent"
        card_view:layout_constraintStart_toStartOf="parent"
        card_view:layout_constraintTop_toTopOf="parent">
    
        <com.mapbox.mapboxsdk.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            mapbox:mapbox_cameraTargetLat="40.73581"
            mapbox:mapbox_cameraTargetLng="-73.99155"
            mapbox:mapbox_cameraZoom="11"
            mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" />
    
    </android.support.v7.widget.CardView>
    
    
    </android.support.constraint.ConstraintLayout>
    

    【讨论】:

    • 所以问题似乎是我将此视图覆盖到 Unity 相机视图上。这似乎搞砸了。 mapView 总是最终变得透明并且没有显示在相机预览中。无论如何要解决这个问题?
    • 这似乎是与圆角mapView 不同的问题。你能像上面那样把角弄圆吗?截取您设备的屏幕截图并发布到 Imgur,以便我可以看到您在说什么 @Rubinstd ?您当前的 XML 文件是什么样的? mapbox.com/contact/support/#products/android 也是 Mapbox 帮助的重要资源
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多