学习笔记 Tianmao 篇 recyclerView 辅助的RecycleAdapterImpl类(适配自定义home三型)

来源:互联网 发布:传奇db数据 编辑:程序博客网 时间:2024/05/28 09:32

一 .这里是承接学习笔记 Tianmao 篇 RecyclerView.Adapter 的封装

二.这里只贴RecycleAdapterImpl类代码对应的javabean 和 布局 以及 相应的效果

三.规格为 效果图—Impl类 —javabean —布局—-style

1.效果图

这里写图片描述
这里写图片描述

2.Impl类

package pers.lijunxue.tianmao.adapter;import android.content.Context;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.TextView;import com.squareup.picasso.Picasso;import java.util.List;import pers.lijunxue.tianmao.R;import pers.lijunxue.tianmao.javabean.HomeThirdViewBean;import pers.lijunxue.tianmao.javabean.HomeThirdViewItemBean;/** *  适配 title 加3图片 与 4型有区别 * Created by rabook on 2016/10/25. */public class HomeThirdRecycleAdapterImpl extends BaseRecycleAdapter {    private final int VIEW_TYPE = 3;    private LayoutInflater layoutInflater;    public HomeThirdRecycleAdapterImpl(List list, Context context) {        super(list, context);    }    @Override    RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {        layoutInflater = LayoutInflater.from(parent.getContext());        View view = layoutInflater.inflate(R.layout.home_item_card_view_three, parent, false);        return new HomeThirdViewHolder(view);    }    @Override    void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {        HomeThirdViewHolder homeThirdViewHolder = (HomeThirdViewHolder)holder;        homeThirdViewHolder.onBind(super.getList(),position,super.getContext());    }    // 绑定item布局文件中的子控件 监听动作    class HomeThirdViewHolder extends RecyclerView.ViewHolder {        private HomeThirdViewBean homeThirdViewBean;        private HomeThirdViewItemBean [] items ;        private TextView title ;        private ImageView[] images;        private int [] imgview_ids = {                R.id.imgview_big,                R.id.imgview_small_top,                R.id.imgview_small_bottom        };        public HomeThirdViewHolder(View itemView) {            super(itemView);            items = new HomeThirdViewItemBean[3];            images = new ImageView[3];            title = (TextView) itemView.findViewById(R.id.text_title);            for (int i = 0;i < images.length ; i++) {                images[i] = (ImageView) itemView.findViewById(imgview_ids[i]);            }        }        public void onBind(List list , int position, Context context){            homeThirdViewBean =  (HomeThirdViewBean)list.get(position);            items [0] = homeThirdViewBean.getCpOne();            items [1] = homeThirdViewBean.getCpTwo();            items [2] = homeThirdViewBean.getCpThree();            for (int i = 0; i<items.length;i++) {                ImageView imageView = images[i];                //使用网络图片                Picasso.with(context).load(items[i].getImgUrl()).into(imageView);                title.setText(homeThirdViewBean.getTitle());            }        }    }}

3.javabean

1.外层

package pers.lijunxue.tianmao.javabean;/**真正的recyclor中的javabean * Created by rabook on 2016/10/25. */public class HomeThirdViewBean extends ViewBean {    public static final int TYPE = 3;    private int id;    private String title;    private HomeThirdViewItemBean cpOne;    private HomeThirdViewItemBean cpTwo;    private HomeThirdViewItemBean cpThree;    //jason在解析时候构造的是无参构造函数  所以这里要注意    public HomeThirdViewBean()    {        super(TYPE);    }    public HomeThirdViewBean(int id, String title,  HomeThirdViewItemBean cpOne,                                                    HomeThirdViewItemBean cpTwo,                                                    HomeThirdViewItemBean cpThree) {        super(TYPE);        this.id = id;        this.title = title;        this.cpOne = cpOne;        this.cpTwo = cpTwo;        this.cpThree = cpThree;    }    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getTitle() {        return title;    }    public void setTitle(String title) {        this.title = title;    }    public HomeThirdViewItemBean getCpOne() {        return cpOne;    }    public void setCpOne(HomeThirdViewItemBean cpOne) {        this.cpOne = cpOne;    }    public HomeThirdViewItemBean getCpTwo() {        return cpTwo;    }    public void setCpTwo(HomeThirdViewItemBean cpTwo) {        this.cpTwo = cpTwo;    }    public HomeThirdViewItemBean getCpThree() {        return cpThree;    }    public void setCpThree(HomeThirdViewItemBean cpThree) {        this.cpThree = cpThree;    }}

2.内层

package pers.lijunxue.tianmao.javabean;/**用于获取网络数据,HomeThirdView中的数据,子bean * Created by rabook on 2016/10/25. */public class HomeThirdViewItemBean {    private int id;    private String title;    private String imgUrl;    public HomeThirdViewItemBean(int id, String title, String imgUrl) {        this.id = id;        this.title = title;        this.imgUrl = imgUrl;    }    public HomeThirdViewItemBean() {    }    public int getId() {        return id;    }    public void setId(int id) {        this.id = id;    }    public String getTitle() {        return title;    }    public void setTitle(String title) {        this.title = title;    }    public String getImgUrl() {        return imgUrl;    }    public void setImgUrl(String imgUrl) {        this.imgUrl = imgUrl;    }}

4.布局

<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardView    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_gravity="center"    android:gravity="center"    android:layout_width="match_parent"    android:layout_height="wrap_content"    app:cardBackgroundColor="#fff"    app:contentPadding="10dp"    app:cardCornerRadius="4dp">    <LinearLayout        android:orientation="vertical"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:id="@+id/text_title"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:textSize="20sp"            android:textColor="@color/black"            android:paddingTop="1dp"            />        <View            style="@style/line_vertical"            android:layout_marginBottom="1dp"            android:layout_marginTop="1dp"></View>        <LinearLayout            android:orientation="horizontal"            android:layout_width="match_parent"            android:layout_height="wrap_content">            <LinearLayout                android:id="@+id/layout_left"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:orientation="vertical"                >                <ImageView                    android:id="@+id/imgview_small_top"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    />                <View                    android:id="@+id/line2"                    style="@style/line_vertical"                    ></View>                <ImageView                    android:id="@+id/imgview_small_bottom"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    />            </LinearLayout>            <View                android:id="@+id/line"                style="@style/line_horizontal"                android:layout_marginLeft="5dp"                android:layout_marginRight="5dp"                />            <ImageView                android:id="@+id/imgview_big"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                />        </LinearLayout>    </LinearLayout></android.support.v7.widget.CardView>

5.style

line_vertical
line_horizontal
line

    <!--设置cardview中的分割线的类型-->    <style name="line">        <item name="android:background">@color/bg_color</item>    </style>    <style name="line_vertical" parent="line">        <item name="android:layout_width">match_parent</item>        <item name="android:layout_height">1dp</item>    </style>    <style name="line_horizontal" parent="line">        <item name="android:layout_width">1dp</item>        <item name="android:layout_height">fill_parent</item>        <item name="android:layout_gravity">center_horizontal</item>    </style>
0 0
原创粉丝点击