【发布时间】:2020-09-03 15:59:15
【问题描述】:
我正在尝试构建一个带有阴影的tooltip,如下图所示:
我可以通过使用图像作为background 来做到这一点。但我无法对其应用阴影。因此,在搜索后我找到了this article,它使用MaterialCardView 并将MaterialShapeDrawable 作为background 应用到它。
我已经尝试了以下代码:
val shapeDrawable = MaterialShapeDrawable()
val shapeAppearanceModel =
ShapeAppearanceModel.builder().setBottomEdge(TriangleEdgeTreatment(20f, false)).build()
shapeDrawable.shapeAppearanceModel = shapeAppearanceModel
materialDialog.background = shapeDrawable
XML 文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/width_custom_marker"
android:layout_height="100dp"
android:padding="16dp"
tools:ignore="Overdraw">
<com.google.android.material.card.MaterialCardView
android:id="@+id/materialCard"
android:layout_width="@dimen/width_custom_marker"
android:layout_height="50dp" />
</RelativeLayout>
我的问题是,在为这个对象false 设置inside 标志TriangleEdgeTreatment(30f, true) 时,它不能按预期工作。但是,使用true 设置标志可以正常工作。
TriangleEdgeTreatment(30f, false)
TriangleEdgeTreatment(30f, true)
提前致谢!
【问题讨论】:
-
尝试添加 android:clipToPadding="false" 和 android:clipToPadding="false" 到父视图
-
我之前试过。它不能解决问题。
标签: android tooltip material-components-android materialcardview