首页 > 解决方案 > 让谷歌地图走投无路

问题描述

我想创建bottomsheetdialog 用于从地图中选择一个地方。但是在我的设计中,谷歌地图顶部是角落。如果我让SupportMapFragment 背景的父级顶部角落SupportMapFragmnet rectangle.not 角落。有些人知道如何实现?
在此处输入图像描述

在我的应用程序中是这样的:在此处输入图像描述

<RelativeLayout
android:id="@+id/root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="570dp"
android:maxHeight="570dp"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="FragmentTagUsage" />

<LinearLayout
    android:layout_marginTop="16dp"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:layout_marginLeft="34dp"
        android:layout_marginRight="34dp"
        app:cardCornerRadius="10dp"
        android:layout_width="match_parent"
        android:layout_height="40dp">

        <EditText
            android:id="@+id/edit_text_name"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:textColorHint="@color/grey"
            android:fontFamily="@font/poppins_semibold"
            android:textSize="12sp"
            android:textColor="@color/black"
            android:background="@color/transparent"
            android:hint="@string/set_name_to_place"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:importantForAutofill="no"
            android:inputType="text" />

    </androidx.cardview.widget.CardView>


    <androidx.cardview.widget.CardView
        android:layout_gravity="end"
        android:id="@+id/card_view_my_location"
        android:layout_margin="18dp"
        android:layout_width="40dp"
        android:layout_height="40dp"
        app:cardCornerRadius="30dp"
        app:cardElevation="4dp">

        <ImageView
            android:layout_gravity="center"
            app:srcCompat="@drawable/ic_my_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="ContentDescription" />

    </androidx.cardview.widget.CardView>


</LinearLayout>

<LinearLayout
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/button_add"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="@dimen/basic_card_margin"
        android:layout_marginRight="@dimen/basic_card_margin"
        android:background="@drawable/background_button_selector"
        android:text="@string/add"
        android:textAllCaps="false"
        android:textColor="@color/white" />

    <View
        android:background="@color/transparent"
        android:layout_width="match_parent"
         android:layout_height="35dp"/>
  </LinearLayout>

</RelativeLayout>

那么我怎样才能像我给静态高度一样制作底片高度

标签: androidgoogle-maps

解决方案


将添加一个扩展功能以应用于任何视图。否则,您可以提取方法的内容并单独应用。将此应用于您的根布局。

/**
 * Rounds the top corners of the View
 */
fun View.setTopRoundedCorners(radius: Float) {
    outlineProvider = object : ViewOutlineProvider() {
        override fun getOutline(view: View, outline: Outline) {
            outline.setRoundRect(
                0, 0, view.width, (view.height + radius).toInt(), radius
            )
        }
    }
    clipToOutline = true
}


推荐阅读