gpt4 book ai didi

android - 卡片查看 Material 波纹?

转载 作者:搜寻专家 更新时间:2023-11-01 08:45:29 27 4
gpt4 key购买 nike

我正在开发 Material Design 界面。我有一些卡片,我希望在单击时产生链式 react 。我已经按照谷歌所说的做了,但没有任何反应。这是我的代码:

<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"
/>

最佳答案

看看我的示例 (API<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'

卡片 View 选择器(包装的 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>

关于android - 卡片查看 Material 波纹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28800649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com