Android Lollipop CardView 上的波纹效果 [英] Ripple effect on Android Lollipop CardView

查看:35
本文介绍了Android Lollipop CardView 上的波纹效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过在活动 XML 文件中设置 android:backgound 属性来让 CardView 在触摸时显示涟漪效果 此处 在 Android 开发人员页面上,但它不起作用.根本没有动画,但是调用了onClick中的方法.我还尝试按照here的建议创建一个ripple.xml文件,但结果相同.

I'm trying to get a CardView to display the ripple effect when touched by setting the android:backgound attribute in the activity XML file as described here on the Android Developers page, but it isn't working. No animation at all, but the method in onClick is called. I've also tried creating a ripple.xml file as suggested here, but same result.

出现在活动的 XML 文件中的 CardView:

The CardView as it appears in the activity's XML file:

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="155dp"
    android:layout_height="230dp"
    android:elevation="4dp"
    android:translationZ="5dp"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:onClick="showNotices"
    android:background="?android:attr/selectableItemBackground"
    android:id="@+id/notices_card"
    card_view:cardCornerRadius="2dp">

</android.support.v7.widget.CardView> 

我对 Android 开发比较陌生,所以我可能犯了一些明显的错误.

I'm relatively new to android development, so I might have made a few obvious mistakes.

推荐答案

你应该在 CardView 中添加以下内容:

You should add following to CardView:

android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"

这篇关于Android Lollipop CardView 上的波纹效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆