gpt4 book ai didi

android - MPAndroidChart - MarkerView 不显示阴影

转载 作者:行者123 更新时间:2023-12-04 23:41:02 33 4
gpt4 key购买 nike

我的应用显示折线图和自定义 MarkerView。 MarkerView 的一个问题是阴影不起作用。相同的代码适用于 Activity 的布局。但是,如果我将其复制到 MarkerView 的布局中,则在我运行应用程序时不会显示阴影。
为了显示阴影,我将高度设置为 5dp,并在 View 上设置背景颜色。然后,对于它的父 View ,我将 padding 设置为 5dp,将 clipToBounds 设置为 false。如下所示:

    <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/line_chart_view"
app:layout_constraintBottom_toBottomOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:padding="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text"
android:elevation="10dp"
android:background="#FFFFFFFF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

最佳答案

所以对于我的markerview,这个海拔是行不通的。原因是因为在引擎盖下所有东西都将绘制在 Canvas 上。所以我们所做的基本上是在 MarkerView XML 布局中创建一个阴影:
image
markerview.xml(可绘制):

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient
android:startColor="#FF808080"
android:endColor="#00000000"
android:gradientRadius="11dp"
android:type="radial" />
</shape>
</item>

<item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="6dp">
<shape android:shape="oval">
<solid android:color="@android:color/holo_blue_bright" />
<stroke
android:width="3dp"
android:color="@color/white" />
<size
android:width="20dp"
android:height="20dp" />
</shape>
</item>
</layer-list>
如您所见,顶部、左侧、右侧、底部用于操纵阴影。我知道您正在使用 textview,但也许这可以让您深入了解它的实际工作原理。
希望这可以帮助其他也在这个问题上苦苦挣扎的人。

关于android - MPAndroidChart - MarkerView 不显示阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63994086/

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