我尝试将Material Design的高程概念应用到我的RecyclerView。
对于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>
当我选择项目时,我以编程方式将drawable应用于背景以获得效果,并根据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设置背景,那么它的效果很好。阴影像预期的那样被放大。
有什么问题?
答案 0 :(得分:2)
2014年https://issuetracker.google.com/issues/37008403
是麻烦决定1
不要将具有透明度的颜色用于背景CardView
决定2
在CardView中设置View或ViewGroup的背景而不是此cardView,然后一切正常