CardView触摸反馈
2017-09-05 本文已影响28人
By_syk
实践 Cards - Components - Material design guidelines 文档中 Card raised elevation 效果。
Card elevationbuild.gradle
compile 'com.android.support:cardview-v7:25.3.1'
layout/activity_main.xml
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:stateListAnimator="@drawable/card"
android:clickable="true"
cardview:cardElevation="2dp">
...
</android.support.v7.widget.CardView>
drawable/card.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="false">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="0dp"
android:valueType="floatType" />
</item>
<item android:state_enabled="true" android:state_pressed="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="8dp"
android:valueType="floatType" />
</item>
</selector>