仿京东的分类页面

package com.example.jingdong.View.Frament.Frament;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;

import com.example.jingdong.Pareset.FenLeiP;
import com.example.jingdong.R;
import com.example.jingdong.View.Frament.Bean.FenLeiListBean;
import com.example.jingdong.View.Frament.Bean.FenleiRightBean;
import com.example.jingdong.View.Frament.Jiekou.FenLeiPjiekou;
import com.example.jingdong.View.Frament.shipei.FenleiListAdapetshipei;
import com.example.jingdong.View.Frament.util.Apiutil;

/**
 * Created by Administrator on 2018/2/20 0020.
 */

public class FamentFenlei extends Fragment implements FenLeiPjiekou{

    private ListView fenlei_listview;
    private FrameLayout fenlei_fl;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layoutfenlei, container, false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        fenlei_listview = getActivity().findViewById(R.id.fenlei_listview);
        fenlei_fl = getActivity().findViewById(R.id.fenlei_fl);


        //首先显示左边的数据

        FenLeiP fenLeiP=new FenLeiP(this);
        fenLeiP.getFen(Apiutil.FenleiListview);


    }


    @Override
    public void Fen(final FenLeiListBean fenLeiListBean) {

        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                FenleiListAdapetshipei fenleiListAdapetshipei=new FenleiListAdapetshipei(getActivity(),fenLeiListBean);
                fenlei_listview.setAdapter(fenleiListAdapetshipei);
                fenlei_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        //使用fragment替换右边frameLayout....fragment之间的传值
                        FramentFenleiRight fragmentFenLeiRight = FramentFenleiRight.getInstance(fenLeiListBean.getData().get(position).getCid());


                        getChildFragmentManager().beginTransaction().replace(R.id.fenlei_fl,fragmentFenLeiRight).commit();
                    }
                });
            }
        });

    }

    @Override
    public void Right(FenleiRightBean fenleiRightBean) {

    }
}

//布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/fenlei_listview"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent"></ListView>
        <FrameLayout
            android:id="@+id/fenlei_fl"
            android:layout_width="0dp"
            android:layout_weight="3"
            android:layout_height="match_parent"></FrameLayout>
    </LinearLayout>

</LinearLayout>



然后右边半部分
package com.example.jingdong.View.Frament.Frament;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.jingdong.Pareset.FenLeiP;
import com.example.jingdong.R;
import com.example.jingdong.View.Frament.Bean.FenLeiListBean;
import com.example.jingdong.View.Frament.Bean.FenleiRightBean;
import com.example.jingdong.View.Frament.Jiekou.FenLeiPjiekou;
import com.example.jingdong.View.Frament.shipei.FenleiRightShipei;
import com.example.jingdong.View.Frament.util.Apiutil;

/**
 * Created by Administrator on 2018/2/24 0024.
 */

public class FramentFenleiRight extends Fragment implements FenLeiPjiekou{

    private RecyclerView fenlei_right_recy;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.framentfenleiright, container, false);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        fenlei_right_recy = getActivity().findViewById(R.id.fenlei_right_recy);
        FenLeiP fenLeiP=new FenLeiP(this);
        //获取传递的cid
        int cid = getArguments().getInt("cid", -1);
        if (cid != -1) {
            //获取展示的数据
            fenLeiP.getChildData(Apiutil.FenleiZI,cid);
        }
    }

    public static FramentFenleiRight getInstance(int cid) {
        FramentFenleiRight fragmentFenLeiRight=new FramentFenleiRight();

        Bundle bundle = new Bundle();
        bundle.putInt("cid",cid);
        fragmentFenLeiRight.setArguments(bundle);

        return fragmentFenLeiRight;
    }

    @Override
    public void Fen(FenLeiListBean fenLeiListBean) {

    }

    @Override
    public void Right(final FenleiRightBean fenleiRightBean) {
        getActivity().runOnUiThread(new Runnable() {

            private FenleiRightShipei fenLeiRecyclerOutAdapter;

            @Override
            public void run() {
                fenLeiRecyclerOutAdapter = new FenleiRightShipei(getActivity(), fenleiRightBean);
                fenlei_right_recy.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL, false));

                fenlei_right_recy.setAdapter(fenLeiRecyclerOutAdapter);

            }
        });
        //设置适配器

    }
}
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:scrollbars="none"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_marginTop="50dp"
                android:src="@drawable/timg"
                android:scaleType="fitXY"
                android:layout_width="match_parent"
                android:layout_height="100dp" />

            <android.support.v7.widget.RecyclerView
                android:layout_marginTop="50dp"
                android:id="@+id/fenlei_right_recy"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </android.support.v7.widget.RecyclerView>


        </LinearLayout>

    </ScrollView>




</LinearLayout>
 

//子分类头适配器
package com.example.jingdong.View.Frament.shipei;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.jingdong.R;
import com.example.jingdong.View.Frament.Bean.FenleiRightBean;
import com.example.jingdong.View.Frament.Jiekou.Item;
import com.example.jingdong.View.Frament.Main.ShangPinLieBiaoActivity;
import com.example.jingdong.View.Frament.viewhodel.FenleirightView;

/**
 * Created by Administrator on 2018/2/24 0024.
 */

public class FenleiRightShipei extends RecyclerView.Adapter<FenleirightView> {
    Context context;
    FenleiRightBean fenleiRightBean;
    private FenleiRightZishipei fenRecyclerInnerAdapter;

    public FenleiRightShipei(Context context, FenleiRightBean fenleiRightBean) {
        this.context=context;
        this.fenleiRightBean=fenleiRightBean;
    }

    @Override
    public FenleirightView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fenlei_right_tou, parent, false);
        FenleirightView fenleirightView=new FenleirightView(view);
        return fenleirightView;
    }

    @Override
    public void onBindViewHolder(FenleirightView holder, int position) {
            holder.fenlei_right_tou_tv.setText(fenleiRightBean.getData().get(position).getName());
        //设置布局管理器
        holder.fenlei_right_tou_re.setLayoutManager(new GridLayoutManager(context,3));
        //给里面的recyclerView设置适配器
        fenRecyclerInnerAdapter = new FenleiRightZishipei(context, fenleiRightBean);
        holder.fenlei_right_tou_re.setAdapter(fenRecyclerInnerAdapter);
        fenRecyclerInnerAdapter.dianji(new Item() {
            @Override
            public void dianji(int position) {
                    //点击商品跳转到列表页面


              Intent intent=new Intent(context, ShangPinLieBiaoActivity.class);
                String name = fenleiRightBean.getData().get(position).getList().get(position).getName();
                intent.putExtra("keywords",name);
                context.startActivity(intent);

            }

            @Override
            public void changan(int position) {

            }
        });
    }

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


//子分类尾适配器
package com.example.jingdong.View.Frament.shipei;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.example.jingdong.R;
import com.example.jingdong.View.Frament.Bean.FenleiRightBean;
import com.example.jingdong.View.Frament.Jiekou.Item;
import com.example.jingdong.View.Frament.viewhodel.RightZiview;

/**
 * Created by Administrator on 2018/2/24 0024.
 */

public class FenleiRightZishipei extends RecyclerView.Adapter<RightZiview>{
    Context context;
    Item item;
    FenleiRightBean fenleiRightBean;
    public FenleiRightZishipei(Context context, FenleiRightBean fenleiRightBean) {
        this.context=context;
        this.fenleiRightBean=fenleiRightBean;
    }

    @Override
    public RightZiview onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fenleirightzi, parent, false);
        RightZiview rightZiview=new RightZiview(view);
        return rightZiview;
    }

    @Override
    public void onBindViewHolder(RightZiview holder, final int position) {
        FenleiRightBean.DataBean dataBean = fenleiRightBean.getData().get(position);
        Glide.with(context).load(dataBean.getList().get(position).getIcon()).into(holder.fenlei_right_zi_img);
        holder.fenlei_right_zi_tv.setText(dataBean.getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.dianji(position);
            }
        });

    }
public  void dianji(Item item)
{
    this.item=item;
}
    @Override
    public int getItemCount() {
        return fenleiRightBean.getData().size();
    }
}

子分类头布局 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/fenlei_right_tou_tv"

        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/fenlei_right_tou_re"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</LinearLayout>
//子布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"

    android:layout_height="wrap_content">
<ImageView
    android:id="@+id/fenlei_right_zi_img"
    android:layout_width="50dp"
    android:layout_height="50dp" />
    <TextView
        android:id="@+id/fenlei_right_zi_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>
 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值