gpt4 book ai didi

android - 为 MaterialCardView 设置 "outside"底部边缘无法按预期工作

转载 作者:行者123 更新时间:2023-12-04 09:59:35 31 4
gpt4 key购买 nike

我正在尝试构建一个带有阴影的tooltip,如下图所示:

enter image description here

我能够通过将图像用作背景 来做到这一点。但我无法对其应用阴影。所以,在搜索之后我找到了 this article ,它使用 MaterialCardView 并将 MaterialShapeDrawable 应用于它作为 背景

我试过下面的代码:

    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>

我的问题 是,在为这个对象 TriangleEdgeTreatment(30f, true) 设置 inside 标志为 false 时> 它没有按预期工作。但是,使用 true 设置标志可以正常工作。

三角边处理(30f, false)

enter image description here

三角边处理(30f, true)

enter image description here

提前致谢!

最佳答案

我可以使用:

  <LinearLayout
android:clipChildren="false"
android:clipToPadding="false"
android:padding="16dp"
..>

<com.google.android.material.card.MaterialCardView
../>

并应用TriangleEdgeTreatment:

float size = getResources().getDimension(R.dimen.triangle_size); //16dp
TriangleEdgeTreatment triangleEdgeTreatment = new TriangleEdgeTreatment(size,false);

MaterialCardView cardView = findViewById(R.id.card);
cardView.setShapeAppearanceModel(cardView.getShapeAppearanceModel()
.toBuilder()
.setBottomEdge(triangleEdgeTreatment)
.build());

enter image description here

关于android - 为 MaterialCardView 设置 "outside"底部边缘无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61859676/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com