美文网首页
CardView触摸反馈

CardView触摸反馈

作者: By_syk | 来源:发表于2017-09-05 10:14 被阅读28次

    实践 Cards - Components - Material design guidelines 文档中 Card raised elevation 效果。

    Card elevation

    build.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>
    

    相关文章

      网友评论

          本文标题:CardView触摸反馈

          本文链接:https://www.haomeiwen.com/subject/izqujxtx.html