星空网 > 软件开发 > 操作系统

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.

<?"1.0" encoding="utf-8"?>
<RelativeLayout android="http://schemas.android.com/apk/res/android"
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>


 



原标题:RecyclerView 结合 CardView 使用(二)

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

营销节点:https://www.goluckyvip.com/tag/14635.html
中国生产:https://www.goluckyvip.com/tag/14636.html
货物暂停清关:https://www.goluckyvip.com/tag/14637.html
英国女王:https://www.goluckyvip.com/tag/14638.html
跨境支付利好:https://www.goluckyvip.com/tag/14639.html
欧洲税务政策:https://www.goluckyvip.com/tag/1464.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流