RecyclerView 结合 CardView 使用(二)

上一篇的基础上,修改了,CardView的布局和点击效果

总结:

CardView的奇葩属性 :app:cardPreventCornerOverlap="false" 和园角边框重叠的效果;

实现点击事件是CardView的子布局!

注意:一个细节,没明白。

在CardView控件的属性下,android:foreground="?android:attr/selectableItemBackground"
但是其他控件实现点击水波纹效果的是 android:background="?android:attr/selectableItemBackground"

1. RecyclerViewAdapter.java

RelativeLayout cardView;//修改ImageView news_photo;TextView news_title;TextView news_desc;Button share;Button readMore;

public NewsViewHolder(final View itemView) {    super(itemView);    cardView= (RelativeLayout) itemView.findViewById(R.id.card_view);

2. news_item.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"    android:layout_height="match_parent"    android:padding="20dp"  >

    <android.support.v7.widget.CardView

        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:foreground="?android:attr/selectableItemBackground"        android:clickable="false"        app:cardCornerRadius="5dp"        app:cardPreventCornerOverlap="false"        app:elevation="2dp"        >

        <RelativeLayout            android:id="@+id/card_view"            android:background="?android:attr/selectableItemBackground"            android:layout_width="match_parent"            android:layout_height="wrap_content">            <RelativeLayout                android:id="@+id/news_header"                android:layout_width="match_parent"                android:layout_height="wrap_content">                <ImageView                    android:id="@+id/news_photo"                    android:scaleType="centerCrop"                    android:layout_alignParentTop="true"                    android:layout_width="match_parent"                    android:layout_height="150dp"/>                <TextView                    android:id="@+id/news_title"                    android:layout_alignParentBottom="true"                    android:layout_alignParentLeft="true"                    android:maxLines="1"                    android:textSize="20sp"                    android:padding="5dp"                    android:textColor="#ffffff"                    android:gravity="center"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"/>            </RelativeLayout>
            <TextView                android:id="@+id/news_desc"                android:maxLines="2"                android:layout_below="@+id/news_header"                android:layout_margin="15dp"                android:layout_width="wrap_content"                android:layout_height="wrap_content"/>            <LinearLayout                android:orientation="horizontal"                android:layout_below="@+id/news_desc"                android:layout_width="match_parent"                android:layout_height="wrap_content">                <Button                    android:id="@+id/btn_share"                    android:text="SHARE"                    android:background="#00000000"                    android:layout_marginLeft="10dp"                    android:layout_marginRight="20dp"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content" />                <Button                    android:id="@+id/btn_more"                    android:background="#00000000"                    android:textColor="#7AD3E0"                    android:text="READ MORE"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content" />            </LinearLayout>

        </RelativeLayout>

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

</RelativeLayout>
 
时间: 2024-08-10 19:18:07

RecyclerView 结合 CardView 使用(二)的相关文章

Android学习笔记二十九之SwipeRefreshLayout、RecyclerView和CardView

Android学习笔记二十九之SwipeRefreshLayout.RecyclerView和CardView 前面我们介绍了AlertDialog和几个常用的Dialog,ProgressDialog进度条提示框.DatePickerDialog日期选择对话框和TimePickerDialog时间选择对话框.这一节我们介绍几个新的API控件SwipeRefreshLayout.RecyclerView和CardView,这几个API控件都是google在Android5.0推出的.下面我们来学

【android】使用RecyclerView和CardView,实现知乎日报精致布局

完整代码,请参考我的博客园客户端,git地址:http://git.oschina.net/yso/CNBlogs 在写博客园客户端的时候,突然想到,弄个知乎日报风格的简单清爽多好!不需要那么多繁杂的信息干扰视野. 先贴上效果图,左边是知乎日报的,右边是本方案的 本文所使用的ide是androidStudio 首先我们需要在项目中,引入RecyclerView.CardView 在build.gradle的 dependencies 添加两条引用语句,如 dependencies { compi

Android RecyclerView 和 CardView简单使用

Android 5.0之后Android新增加的两个UI控件RecyclerView,CardView. RecyclerView可以看出是ListView的加强版,能够更加灵活的使用.支持动画等 CardView则是Google提供的一个卡片式视图组件,可以定义如边角的弧度.阴影等属性.从本质上看,可以将CardView看做是FrameLayout在自身之上添加了圆角和阴影效果. 要使用这两个UI控件我们需要先在Android Studio 中添加相应的库: 之后要有两个布局文件: main_

Android L中的RecyclerView 、CardView 、Palette的使用

<Material Design>提到,Android L版本中新增了RecyclerView.CardView .Palette.RecyclerView.CardView为用于显示复杂视图的新增Widget.Palette作为调色板类,可以让你从图像中提取突出的颜色. RecyclerView RecyclerView作为替代ListView使用,RecyclerView标准化了ViewHolder,ListView中convertView是复用的,在RecyclerView中,是把Vie

RecyclerView 结合 CardView 使用

准备工作:导入 1.activity_mian.xml <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:scrollbars="vertical" android:layout_width="match_parent" android:layout_height="match_parent"/> 2.aci

Android RecyclerView And CardView

Google I/O 2014大会公布Android L系统,还有Material Design全新的设计风格.而Material Design卡片式的设计.Google Play应用商店和G+ APP已经变成这样的卡片式的风格.为了配合Material Design, Google特意在SDK中加入了RecyclerView 和 CardView,只是它加入在Support-V7库中,可能是为了兼容旧版本号吧.Google官方已经说明确怎么用了,这里: https://developer.an

Android L 之 RecyclerView 、CardView 、Palette

转: http://blog.csdn.net/xyz_lmn/article/details/38735117 <Material Design>提到,Android L版本中新增了RecyclerView.CardView .Palette.RecyclerView.CardView为用于显示复杂视图的新增Widget.Palette作为调色板类,可以让你从图像中提取突出的颜色. RecyclerView RecyclerView作为替代ListView使用,RecyclerView标准化

Android Material Design系列之RecyclerView和CardView

去年很早之前,我就讲解过RecyclerView的使用,今天我们就在讲解CardView的时候,顺便再把RecyclerView同时讲解一下.RecyclerView.CardView为用于显示复杂视图的新增Widget.接下来看看如何使用吧. RecyclerView RecyclerView介绍 RecyclerView作为替代ListView使用,它更先进,更灵活,RecyclerView标准化了ViewHolder,ListView中convertView是复用的,在RecyclerVi

Android5.x 新控件之RecyclerView,CardView,Palette的使用

『转载注明出处:http://blog.csdn.net/feiduclear_up/article/details/46439005 CSDN废墟的树』 自Android5.0发布以来,谷歌推出全新的Material Desigen设计风格,时过一年多了,在国内也看到很多应用在慢 慢适应MD设计风格.其中比较好的app就是网易新闻客户端了,其设计风格基本符合MD要求.鉴于越来多App采 用MD设计风格,作为吊丝程序员的我们怎能落后呢?那就让我们来学习一些Android5.x新推出的一些控件吧.