【发布时间】:2018-07-09 18:15:45
【问题描述】:
我尝试在我的 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 被很好地应用了,但是阴影被完全移除并且没有被放大! 如果我没有用drawable设置背景,它的效果很好。阴影像预期的那样被放大了。
有什么问题?
【问题讨论】:
-
好像是this的副本。
标签: android kotlin material-design android-drawable android-elevation