我正在开发材料设计界面。我有卡片,我想点击时有涟漪效果。我已经做了谷歌所说的,没有任何反应。这是我的代码:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:elevation="5dp"
android:background="?android:selectableItemBackground">
>
<ImageView
android:id="@+id/blue_image"
android:src="@drawable/blue"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:elevation="8dp"
/>
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:text="And this is a blue card!"
android:elevation="10dp"
/>
答案 0 :(得分:3)
看看我的例子(API&lt; 21)。这与Lollipop涟漪效应类似。
https://www.youtube.com/watch?v=liure-_hlX0&feature=youtu.be
对于这个演示,我使用了这个库: https://github.com/balysv/material-ripple
只需添加到build.gradle:
compile 'com.balysv:material-ripple:1.0.1'
卡片视图选择器(包装的RelativeLayout): list_item_selector.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pressed -->
<item android:drawable="@color/ripplecolorbackground" android:state_pressed="true"/>
<!-- selected -->
<item android:drawable="@color/ripplecolorbackground" android:state_selected="true"/>
<!-- focused -->
<item android:drawable="@color/ripplecolorbackground" android:state_focused="true"/>
<!-- default -->
<item android:drawable="@color/transparent"/>
布局:的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
tools:context=".MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3dp"
card_view:cardPreventCornerOverlap="true">
<com.balysv.materialripple.MaterialRippleLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mrl_rippleColor="@color/rippplecolorlist"
app:mrl_rippleAlpha="0.10"
app:mrl_rippleOverlay="false"
app:mrl_rippleHover="true"
app:mrl_rippleDimension="1dp"
app:mrl_rippleDuration="350">
<RelativeLayout
android:background="@drawable/list_item_selector"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.balysv.materialripple.MaterialRippleLayout>
</android.support.v7.widget.CardView>
颜色的
<color name="ripplecolorbackground">#1A000000</color>
<color name="rippplecolorlist">#26000000</color>
答案 1 :(得分:0)
我创建了一个库,允许自定义每个视图而不影响布局以创建连锁效果
我希望它可以帮到你 https://github.com/xgc1986/RippleViews/blob/master/docs/RippleDrawableHelper.md
此外,该示例正在使用具有此效果的cardViews;)