如何在Android的CardView中添加动画,如果我点击CardView我想要显示一些动画.
这是我为CardView创建的CardView的xml.如何在此内添加动画:
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"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp"
card_view:cardMaxElevation="6dp"
card_view:contentPadding="5dp"
android:layout_margin="5dp"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
android:id="@+id/iv_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:layout_toRightOf="@id/iv_icon"
android:layout_toEndOf="@id/iv_icon"
android:paddingLeft="10dp"
/>
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#848484"
android:layout_below="@id/app_label"
android:layout_toRightOf="@id/iv_icon"
android:layout_toEndOf="@id/iv_icon"
android:textStyle="italic"
android:paddingLeft="10dp"
/>
最佳答案:
将这段代码放在cardview中并创建一个animation.xml并调用
机器人:stateListAnimator = “@动画/动画”
android:foreground="?attr/selectableItemBackground"
android:stateListAnimator="@anim/animation"
android:clickable="true"
animation.xml
android:state_enabled="true"
android:state_pressed="true">
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="6dp"
android:valueType="floatType"/>
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="0"
android:valueType="floatType"/>
同样,您可以使用任何类型的动画
标签:android,android-cardview
来源: https://codeday.me/bug/20190516/1114775.html