适用适配器及布局 选择器

接口中缺少

public interface GetDataInterface {
    @GET("/umIPmfS6c83237d9c70c7c9510c9b0f97171a308d13b611?uri=homepage")
    Call<DataDataBean> getInto();
}



标题布局及适配

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<ImageView
    android:layout_gravity="center"
    android:id="@+id/img5"
    android:layout_width="120dp"
    android:layout_height="50dp" />

    <TextView
        android:gravity="center"
        android:id="@+id/tname"
        android:layout_width="120dp"
        android:layout_height="20dp" />
</LinearLayout>


public class BiaoTiAdapter extends RecyclerView.Adapter<BiaoTiAdapter.MyBiaoTiAdapter>{
    Context context; List<DataDataBean.DataBean.Ad5Bean> ad5;
    private TextView tname;
    private ImageView img5;

    public BiaoTiAdapter(Context context, List<DataDataBean.DataBean.Ad5Bean> ad5) {
        this.context = context;
        this.ad5 = ad5;
    }

    @Override
    public MyBiaoTiAdapter onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.biaotiadapter_layout, null);
        return new MyBiaoTiAdapter(view);
    }

    @Override
    public void onBindViewHolder(MyBiaoTiAdapter holder, int position) {
        Glide.with(context)
                .load(ad5.get(position).getImage())
                .into(img5);
        tname.setText(ad5.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return ad5.size();
    }

    public class MyBiaoTiAdapter extends RecyclerView.ViewHolder {
        public MyBiaoTiAdapter(View itemView) {
            super(itemView);
            tname = itemView.findViewById(R.id.tname);
            img5 = itemView.findViewById(R.id.img5);

        }
    }
}



My 适配及布局

Banner 布局 myadapter_layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.youth.banner.Banner
        android:id="@+id/ba"
        android:layout_width="match_parent"
        android:layout_height="200dp"></com.youth.banner.Banner>
</LinearLayout>

热门活动布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>

<TextView
    android:layout_marginTop="10dp"
    android:textSize="20dp"
    android:text="热门活动"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/img1"
            android:layout_width="220dp"
            android:layout_height="wrap_content" />
        <ImageView
            android:id="@+id/img2"
            android:layout_width="220dp"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>

状态布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <TextView
        android:layout_marginTop="10dp"
        android:textSize="20dp"
        android:text="热门状态"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ImageView
        android:id="@+id/img3"
        android:layout_width="450dp"
        android:layout_height="150dp" />
    <android.support.v7.widget.RecyclerView
        android:layout_marginTop="10dp"
        android:id="@+id/RecyclerView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</LinearLayout>


public class MyAdapter extends RecyclerView.Adapter {
    DataDataBean.DataBean data;
    Context context;
    int a=0;
    int b=1;
    int c=2;
    public static ImageView img1;
    private static ImageView img2;
    private ImageView img3;
    private RecyclerView recyclerView2;
    private RecyclerView recyclerView3;


    public MyAdapter( DataDataBean.DataBean data, Context context) {
        super();
        this.data = data;
        this.context = context;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view;
        if (viewType == a) {
            view = View.inflate(parent.getContext(), R.layout.myadapter_layout, null);
            return new MyViewHolder(view);
        } else if (viewType == b) {
            view = View.inflate(parent.getContext(), R.layout.remen_layout, null);
            return new RightImageHolder(view);
        } else {
            view = View.inflate(parent.getContext(), R.layout.zhuanti_layout, null);
            return new ThreeImageHolder(view);
        }
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int itemViewType = getItemViewType(position);
        switch (itemViewType){
            case 0:
                List<DataDataBean.DataBean.DefaultGoodsListBean> defaultGoodsList = data.getDefaultGoodsList();
                List<String> list=new ArrayList<>();
                for (int i=0;i<defaultGoodsList.size();i++){
                    list.add(defaultGoodsList.get(i).getGoods_img());
                    Log.d("TAG",defaultGoodsList.get(i).getGoods_img());
                }
                MyViewHolder holder1 = (MyViewHolder) holder;
                Banner banner = holder1.banner;

                //设置banner样式
                banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
                //设置图片加载器
                banner.setImageLoader(new GlideImageLoader());
                //设置图片集合
                banner.setImages(list);
                //设置banner动画效果
                banner.setBannerAnimation(Transformer.DepthPage);
                //设置自动轮播,默认为true
                banner.isAutoPlay(true);
                //设置轮播时间
                banner.setDelayTime(1500);
                //设置指示器位置(当banner模式中有指示器时)
                banner.setIndicatorGravity(BannerConfig.CENTER);
                //banner设置方法全部调用完毕时最后调用
                banner.start();
                break;
            case 1:
                List<DataDataBean.DataBean.SubjectsBean.GoodsListBeanX> goodsList = data.getSubjects().get(position).getGoodsList();
                Glide.with(context)
                        .load(goodsList.get(position).getGoods_img())
                        .into(img1);
                Glide.with(context)
                        .load(goodsList.get(position).getGoods_img())
                        .into(img2);
                List<DataDataBean.DataBean.Ad5Bean> ad5 = data.getAd5();
                recyclerView3.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false));

                recyclerView3.setAdapter(new BiaoTiAdapter(context,ad5));
                break;
            case 2:
                List<DataDataBean.DataBean.SubjectsBean> subjects = data.getSubjects();
                Glide.with(context)
                        .load(subjects.get(position).getImage())
                        .into(img3);
                recyclerView2.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false));

                recyclerView2.setAdapter(new ZhuanTiAdapter(context,subjects));
                break;
        }

    }

    @Override
    public int getItemViewType(int position) {

       return position;


    }
    @Override
    public int getItemCount() {
        return 3;
    }


     class MyViewHolder extends RecyclerView.ViewHolder {
         Banner banner;
        public MyViewHolder(View itemView) {
            super(itemView);
            banner = itemView.findViewById(R.id.ba);
        }
    }
    class RightImageHolder extends RecyclerView.ViewHolder {
        public RightImageHolder(View itemView) {
            super(itemView);
             recyclerView3 = itemView.findViewById(R.id.RecyclerView3);
            img1 = itemView.findViewById(R.id.img1);
            img2 = itemView.findViewById(R.id.img2);
        }
    }

    class ThreeImageHolder extends RecyclerView.ViewHolder {
        public ThreeImageHolder(View itemView) {
            super(itemView);
            img3 = itemView.findViewById(R.id.img3);
            recyclerView2 = itemView.findViewById(R.id.RecyclerView2);
        }
    }
    }


专题适配器

public class ZhuanTiAdapter extends RecyclerView.Adapter<ZhuanTiAdapter.MyZhuanTi> {
    Context context;
    List<DataDataBean.DataBean.SubjectsBean> subjects;
    private ImageView img4;
    private List<DataDataBean.DataBean.SubjectsBean.GoodsListBeanX> goodsList;
    private List<DataDataBean.DataBean.SubjectsBean.GoodsListBeanX> goodsList1;

    public ZhuanTiAdapter(Context context, List<DataDataBean.DataBean.SubjectsBean> subjects) {
        this.context = context;
        this.subjects = subjects;
    }

    @Override
    public MyZhuanTi onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.zhuantiadapter_layout, null);
        MyZhuanTi myZhuanTi = new MyZhuanTi(view);
        return myZhuanTi;
    }

    @Override
    public void onBindViewHolder(MyZhuanTi holder, int position) {
        Log.d("TAG","56"+subjects.get(position).getGoodsList().get(position).getGoods_img());
        goodsList = subjects.get(position).getGoodsList();
        Glide.with(context)
                .load(goodsList.get(position).getGoods_img())
                .into(img4);
    }

    @Override
    public int getItemCount() {

        for (int i=0;i<subjects.size();i++){
            goodsList1 = subjects.get(i).getGoodsList();
        }
        return goodsList1.size();
    }

    public class MyZhuanTi extends RecyclerView.ViewHolder {

        public MyZhuanTi(View itemView) {
            super(itemView);
            img4 = itemView.findViewById(R.id.img4);
        }
    }
}

专题布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/img4"
        android:layout_width="200dp"
        android:layout_height="100dp" />
</LinearLayout>








选择器1 select1

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/ac1"/>
    <item android:state_checked="false" android:drawable="@drawable/ac0"/>
    <item  android:drawable="@drawable/ac0" />
</selector>
选择器2

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/abx"/>
    <item android:state_checked="false" android:drawable="@drawable/abw"/>
    <item  android:drawable="@drawable/abw" />
</selector>

选择器3

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/abv"/>
    <item android:state_checked="false" android:drawable="@drawable/abu"/>
    <item  android:drawable="@drawable/abu" />
</selector>

选择器4


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/ac3"/>
    <item android:state_checked="false" android:drawable="@drawable/ac2"/>
    <item  android:drawable="@drawable/ac2" />
</selector>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值