RecyclerView 结合 CardView 使用(二)
2016-01-26 18:13
253 查看
上一篇的基础上,修改了,CardView的布局和点击效果
总结:
CardView的奇葩属性:app:cardPreventCornerOverlap="false"和园角边框重叠的效果;
实现点击事件是CardView的子布局!
注意:一个细节,没明白。
在CardView控件的属性下,android:foreground="?android:attr/selectableItemBackground"
但是其他控件实现点击水波纹效果的是android:background="?android:attr/selectableItemBackground"
1.RecyclerViewAdapter.java
2.news_item.xml
总结:
CardView的奇葩属性:app:cardPreventCornerOverlap="false"和园角边框重叠的效果;
实现点击事件是CardView的子布局!
注意:一个细节,没明白。
在CardView控件的属性下,android:foreground="?android:attr/selectableItemBackground"
但是其他控件实现点击水波纹效果的是android:background="?android:attr/selectableItemBackground"
1.RecyclerViewAdapter.java
RelativeLayoutcardView;//修改 ImageViewnews_photo; TextViewnews_title; TextViewnews_desc; Buttonshare; ButtonreadMore; publicNewsViewHolder(finalViewitemView){ super(itemView); cardView=(RelativeLayout)itemView.findViewById(R.id.card_view);
2.news_item.xml
<?xmlversion="1.0"encoding="utf-8"?> <RelativeLayoutxmlns: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="READMORE" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </RelativeLayout> </android.support.v7.widget.CardView> </RelativeLayout>
相关文章推荐
- samba的用法
- android开发之Handler和HandlerThread用法说明
- 聊聊我对Java内存模型的理解
- 阿拉伯数字转成中文数字 (支持1~9999)
- opencascade 初探
- iocp性能分析
- AttachThreadInput
- Python求索之路3——迭代器&装饰器&生成器&正则
- JAVA八大经典书籍,你看过几本?
- 51CTO稿酬标准2016版正式发布!
- MyBatis入门学习
- Java并发中正确使用volatile
- HDU2089 不要62(数位DP)
- maven学习
- CentOS7 Juno Cinder块重启后 实例起不来 --rescan Exit code: 21
- 2的m次方 内存对齐
- WordPress程序伪静态规则(Nginx/Apache)及二级目录规则
- tuple内部方法
- self.方法和_对变量的引用的区别
- gerrit+http+2