首页 > 解决方案 > 如何为自定义的 android 谷歌地图信息窗口添加阴影

问题描述

我的自定义信息窗口视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardCornerRadius="7dp"
        app:cardElevation="2dp">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:text="test" />
    </androidx.cardview.widget.CardView>

</LinearLayout>

然后我用它:

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

            @Override
            public View getInfoWindow(Marker arg0) {
                View v = getLayoutInflater().inflate(R.layout.layout_marker_title, null);
                TextView tv_title = v.findViewById(R.id.tv_title);
                tv_title.setText(arg0.getTitle());

                return v;
            }

            @Override
            public View getInfoContents(Marker arg0) {
                return null;

            }
        });

但是cardview似乎没有像往常一样有阴影。玩 cardview 的海拔或 translationZ 没有帮助。

为什么cardview的影子在谷歌地图上不起作用?

给我的自定义信息窗口添加阴影的最佳或最简单的方法是什么?

标签: androidgoogle-maps-markers

解决方案


推荐阅读