gpt4 book ai didi

android - 查看 setBackground 与 drawable 删除海拔的阴影

转载 作者:行者123 更新时间:2023-12-02 12:08:17 24 4
gpt4 key购买 nike

我尝试在我的 RecyclerView 中实现 Material Design 的高程概念。

对于 RecyclerView 的每个项目,我都使用它

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="0dp"
android:elevation="2dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
.../>

<CheckBox
.../>
</RelativeLayout>
</android.support.v7.widget.CardView>

当我选择项目时,我以编程方式将可绘制对象应用到背景以获得效果,并按照 Material Design 规范的建议将高度设置为 8dp。
        val draw = ResourcesCompat.getDrawable(resources, R.drawable.selected_task, null)
draw?.setColorFilter(task.color.aRGB.toInt(), PorterDuff.Mode.OVERLAY)
view.background = draw
view.elevation = 8F

(我用 Kotlin 编码)
可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="@color/select_border"/>
<solid
android:color="@color/select_fill"/>
</shape>

和颜色值
<color name="select_border">#78000000</color>
<color name="select_fill">#32000000</color>

问题是当我选择一个项目时,可绘制对象被很好地应用但阴影被完全移除并且没有被放大!
如果我没有用drawable设置背景,它的效果很好。阴影像预期的那样被放大。

问题是什么 ?

最佳答案

从2014年起是麻烦https://issuetracker.google.com/issues/37008403

决定 1

不要对背景 CardView 使用具有透明度的颜色

决定 2

为 CardView 内的 View 或 ViewGroup 设置背景而不是这个 cardView,然后一切正常

enter image description here

关于android - 查看 setBackground 与 drawable 删除海拔的阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48528576/

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