京东首页

  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      inflate = View.inflate(getContext(), R.layout.shouye, null);
      view = View.inflate(getContext(), R.layout.benner, null);
      MyAbPresenter myAbPresenter = new MyAbPresenter();
      HashMap<String, String> map = new HashMap<>();

      myAbPresenter.getAb(new MyAbModer(),this,map);
      unbinder = ButterKnife.bind(this, view);
      xrecyclerView=inflate.findViewById(R.id.xianshi_XRecyclerView);

      titlbar = inflate.findViewById(R.id.titlbar);
      titl_imageView = titlbar.findViewById(R.id.titl_imageView);
      sousuo = titlbar.findViewById(R.id.shouye_sousuo);

      xrecyclerView.addHeaderView(view);
      xrecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
      //扫码
      titl_imageView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent integer = new Intent(MyApp.context, SaoMaActivity.class);
            startActivity(integer);
          }
      });
      //搜索
      sousuo.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View v) {
              Intent integer = new Intent(MyApp.context, SouActivity.class);
              startActivity(integer);
          }
      });
      //头部渐变
      xrecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              //滑动的距离
              mDistanceY += dy;
              //toolbar的高度
              int toolbarHeight = titlbar.getBottom();

              //当滑动的距离 <= toolbar高度的时候,改变Toolbar背景色的透明度,达到渐变的效果
              if (mDistanceY <= 200) {
                  float scale = (float) mDistanceY /200;
                  float alpha = scale * 255;
                  titlbar.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));

              } else {
                  //将标题栏的颜色设置为完全不透明状态
                  titlbar.setBackgroundResource(R.color.colorWhite);

              }
          }
      });
      return inflate;
  }

  @Override
  public void onDestroyView() {
      super.onDestroyView();
      unbinder.unbind();
   //       轮播图
      if (banner != null) {
          banner.cancel();
          banner = null;
      }

  }
 //成功
  @Override
  public void succeed(AbBaen abBaen) {
      List<AbBaen.DataBean> data = abBaen.getData();
      for (int i = 0; i < data.size(); i++) {
          list.add(data.get(i).getIcon());

      }
      xrecyclerView.setAdapter(new MyAdpter(abBaen));
      //伦布图
      getBanner();
  }
//失败
  @Override
  public void eeror(String ee) {

  }

  public void getBanner() {
      //解耦
      banner.loadData(list).display();//构建者模式返回对象本身
        //        banner.display();
      banner.setBannerClicklistener(new Banner.BannerClicklistener() {
          @Override
          public void onClickListener(int pos) {
              Toast.makeText(getContext(), "pos====" + pos, Toast.LENGTH_SHORT).show();
          }
      });
  }

  //适配器
  class MyAdpter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

      private final AbBaen abBaen;

      public MyAdpter(AbBaen abBaen){
           this.abBaen=abBaen;
        }
      @Override
      public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType){
            case 1:
                View inflate = LayoutInflater.from(getContext()).inflate(R.layout.viewpager, parent, false);
                myViewHoder = new MyViewHoder(inflate);
                return myViewHoder;

            case 2:
                View view = LayoutInflater.from(getContext()).inflate(R.layout.tuijian, parent, false);
                MyViewHoder2 myViewHoder2 = new MyViewHoder2(view);
                return myViewHoder2;


        }


          return null;
      }

      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
         if (holder instanceof MyViewHoder){
             ((MyViewHoder) holder).cdm.start(7200000);
             List<AbBaen.MiaoshaBean.ListBeanX> list = abBaen.getMiaosha().getList();
             MyVpdapder myVpdapder = new MyVpdapder(getContext(),list);
             ((MyViewHoder) holder).xr.setAdapter(myVpdapder);
             ((MyViewHoder) holder).xr.setLayoutManager(new GridLayoutManager(getContext(),2,GridLayoutManager.HORIZONTAL,true));

         }
         if (holder instanceof  MyViewHoder2){

             List<AbBaen.TuijianBean.ListBean> list = abBaen.getTuijian().getList();
             MytuijianAdapter mm=new MytuijianAdapter(getContext(),list);
             ((MyViewHoder2) holder).tuijian.setAdapter(mm);
             ((MyViewHoder2) holder).tuijian.setLayoutManager(new GridLayoutManager(getContext(),2));
         }




      }

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

      @Override
      public int getItemViewType(int position) {

          if (position==0) {
              return 1;
          }
          if (position==1){
              return 2;
          }

          return 0;
      }

      class MyViewHoder extends RecyclerView.ViewHolder {

          private  CountdownView cdm;
          RecyclerView xr;

          public MyViewHoder(View itemView) {
              super(itemView);
              cdm = itemView.findViewById(R.id.cdm);
              xr = itemView.findViewById(R.id.vp_XRecyclerView);

          }


      }



      class MyViewHoder2 extends RecyclerView.ViewHolder {
          XRecyclerView  tuijian;

          public MyViewHoder2(View itemView) {
              super(itemView);
                tuijian=itemView.findViewById(R.id.tui_jian_XRecyclerView);
          }
      }
  }

//秒杀条目适配器

public class MyVpdapder extends RecyclerView.Adapter <MyVpdapder.viewHoder>{

    private final List<AbBaen.MiaoshaBean.ListBeanX> list;
    private final Context context;

    public MyVpdapder(Context context, List<AbBaen.MiaoshaBean.ListBeanX>list){
         this.list=list;
        this.context=context;
     }
    @Override
    public viewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.vp_re_list,parent,false);
        viewHoder viewHoder = new viewHoder(inflate);
        return viewHoder;
    }

    @Override
    public void onBindViewHolder(viewHoder holder, int position) {
        String images = list.get(position).getImages();
        String[] split = images.split(".jpg");
        holder.ss.setImageURI(Uri.parse(split[0] + ".jpg"));

        holder.tilt.setText(list.get(position).getTitle());
    }

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

    class viewHoder extends RecyclerView.ViewHolder{
        SimpleDraweeView ss;
        TextView tilt;
        public viewHoder(View itemView) {
            super(itemView);
            ss= itemView.findViewById(R.id.vp_SimpleDraweeView);
            tilt= itemView.findViewById(R.id.vp_li_tilt);
        }
    }
}
//
//商品推荐条目适配器
public class MytuijianAdapter extends RecyclerView.Adapter <MytuijianAdapter.MviewHoser>{
    private final List<AbBaen.TuijianBean.ListBean> list;
    private final Context context;

    public  MytuijianAdapter(Context context, List<AbBaen.TuijianBean.ListBean>list){
         this.context=context;
         this.list=list;
     }
    @Override
    public MviewHoser onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.tui_jina_list, parent, false);
        MviewHoser mviewHoser = new MviewHoser(inflate);

        return mviewHoser;
    }

    @Override
    public void onBindViewHolder(MviewHoser holder, int position) {
        holder.tex.setText(list.get(position).getTitle());
        String images = list.get(position).getImages();
        String[] split = images.split(".jpg");
        Glide.with(context).load(split[0]+".jpg").into(holder.img);
    }

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

    class MviewHoser extends RecyclerView.ViewHolder {
        ImageView img;
        TextView tex;
        public MviewHoser(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.tui_jian_img);
            tex = itemView.findViewById(R.id.tui_jian_text);
        }
    }


}


            
阅读更多
上一篇RecyofitUtil
下一篇xbanner
想对作者说点什么? 我来说一句

仿京东首页

2018年04月23日 205KB 下载

京东首页HTML+CSS源码

2016年02月26日 1.76MB 下载

仿京东首页沉浸式以及滑动效果

2017年09月13日 15.56MB 下载

京东页面右侧悬浮代码

2013年07月10日 1KB 下载

没有更多推荐了,返回首页

关闭
关闭