京東界面之首頁全部代碼 有點亂

//Java哦

public class Shou extends Fragment{
    private RecyclerView gong;
    private RecyclerView mian;
    private RecyclerView nei;
    private Banner banner;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.shou,null);
        final Banner banner = (Banner) view.findViewById(R.id.banner);
            gong = (RecyclerView) view.findViewById(R.id.gong);
            mian = (RecyclerView) view.findViewById(R.id.mian);
            nei = (RecyclerView) view.findViewById(R.id.nei);



        OkHttp3Util.doGet("http://120.27.23.105/product/getCatagory", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
                if (response.isSuccessful()){
                    final String str = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //1.gson解析
                            Gson gson = new Gson();
                            Gong_Bean gbean = gson.fromJson(str, Gong_Bean.class);
                            List<Gong_Bean.DataEntity> data = gbean.getData();

                            gong.setLayoutManager(new GridLayoutManager(getActivity(),2, OrientationHelper.HORIZONTAL,false));
                            Adapter01 adapter01 = new Adapter01(data,getActivity());

                            gong.setAdapter(adapter01);
                        }
                    });
                }
            }
        });
        OkHttp3Util.doGet("http://120.27.23.105/ad/getAd", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()){
                    final String stri = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //2.gson解析
                            Gson gson = new Gson();
                            Bean gbean2 = gson.fromJson(stri, Bean.class);
                            List<Bean.MiaoshaBean.ListBeanX> list = gbean2.getMiaosha().getList();
                            mian.setLayoutManager(new GridLayoutManager(getActivity(),1,OrientationHelper.HORIZONTAL,false));
                            Adapter adapter = new Adapter(list,getActivity());

                            mian.setAdapter(adapter);
                        }
                    });
                }
            }
        });
        OkHttp3Util.doGet("http://120.27.23.105/ad/getAd", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()){
                    final String strin = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //3.gson解析
                            Gson gson = new Gson();
                            Bean gbean3 = gson.fromJson(strin, Bean.class);
                            List<Bean.TuijianBean.ListBean> list = gbean3.getTuijian().getList();
                            nei.setLayoutManager(new GridLayoutManager(getActivity(),2,OrientationHelper.VERTICAL,false));
                            Adapter03 adapter03 = new Adapter03(list, getActivity());

                            nei.setAdapter(adapter03);

                        }
                    });
                }
            }
        });

        OkHttp3Util.doGet("http://120.27.23.105/ad/getAd", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

                if (response.isSuccessful()){
                    final String s = response.body().string();
                    Log.d("aaa", "run: "+s);
                    getActivity().runOnUiThread(new Runnable() {


                        @Override
                        public void run() {
                            //gson解析
                            Gson gson = new Gson();
                            Bean bean = gson.fromJson(s, Bean.class);
                            List<Bean.DataBean> data = bean.getData();

                            List<String> string = new ArrayList<>();
                            for (int i=0;i<data.size();i++){
                                String icon = data.get(i).getIcon();
                                string.add(icon);

                            }
                            banner.setImageLoader (new Imager());
                            banner.setImages (string);
                            banner.start ();

                        }
                    });

                }
            }
        });
        return view;
    }



}

//Java還有三個界面...大概都是這樣的
public class Mine extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.mine,null);
        return view;
    }
}


//xml四個文件...
//第一個首頁的
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <com.youth.banner.Banner
            android:id="@+id/banner"
            android:layout_width="match_parent"
            android:layout_height="310px"></com.youth.banner.Banner>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/gong"
            android:layout_width="match_parent"
            android:layout_height="410px"></android.support.v7.widget.RecyclerView>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/mian"
            android:layout_width="match_parent"
            android:layout_height="210px"></android.support.v7.widget.RecyclerView>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/nei"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
    </LinearLayout>
</ScrollView>
//第二個
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="#A1CC3B"
    android:layout_height="match_parent">

</LinearLayout>
//第二個第三個第四個都沒有寫.....就定義了一個顏色

//首頁裏面的XML

//第一個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="29dp"
        app:srcCompat="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="100dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:text="TextView" />
</RelativeLayout>
//第二個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="29dp"
        android:src="@mipmap/ic_launcher"/>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="80dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_marginTop="13dp"
        android:text="TextView"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true" />
</RelativeLayout>
//第三個

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="16dp"
        android:src="@mipmap/ic_launcher"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    <TextView
        android:maxLines="2"
        android:minLines="2"
        android:id="@+id/textView2"
        android:layout_width="80dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_marginTop="13dp"
        android:text="TextView"
        android:layout_below="@+id/imageView2"
        android:layout_alignLeft="@+id/imageView2"
        android:layout_alignStart="@+id/imageView2" />
</RelativeLayout>
//有點繁瑣.....

//還有其它類

//Myappter

public class Myappter extends Application {
    @Override
    public void onCreate() {
        super.onCreate ( );
        ImageLoaderConfiguration configuration=new ImageLoaderConfiguration .Builder (this)
                .build ();
        ImageLoader.getInstance ().init (configuration);
    }
}
//Imager

public class Imager extends ImageLoader {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        Glide.with (context).load (path).into (imageView);
    }
}
//Bean類有兩個...
//網址是
http://120.27.23.105/product/getCatagory
//Gong_Bean

http://120.27.23.105/ad/getAd
//Bean

//接下來就是Adapter了...首先是第一個

//上面的代碼Adapter順序有錯誤

//這是第一個應該打的

//名字Adapter02

public class Adapter02 extends RecyclerView.ViewHolder {
    public ImageView img;
    public TextView tex;
    public ImageView img1;
    public TextView tex1;
    public ImageView img2;
    public TextView tex2;
    public Adapter02(View itemView) {

        super(itemView);
        img2 = (ImageView) itemView.findViewById(R.id.imageView2);
        tex2 = (TextView) itemView.findViewById(R.id.textView2);
        tex1 = (TextView) itemView.findViewById(R.id.textView1);
        img1 = (ImageView) itemView.findViewById(R.id.imageView1);
        img = (ImageView) itemView.findViewById(R.id.imageView);
        tex = (TextView) itemView.findViewById(R.id.textView);
    }
}
//第二個

//名字Adapter01

public class Adapter01 extends RecyclerView.Adapter<Adapter02> {
    private List<Gong_Bean.DataEntity> data;
    private Context context;

    public Adapter01(List<Gong_Bean.DataEntity> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public Adapter02 onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.shitu01,null);
        Adapter02 adapter02 = new Adapter02(view);
        //視圖

        return adapter02;
    }

    @Override
    public void onBindViewHolder(Adapter02 holder, int position) {
        holder.tex.setText(data.get(position).getName());
        Glide.with(context).load(data.get(position).getIcon()).into(holder.img);
        //找到控件之後賦值

    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
//第三個

//名字Adapter

public class Adapter extends RecyclerView.Adapter<Adapter02> {
    List<Bean.MiaoshaBean.ListBeanX>  data;
    private Context context;

    public Adapter(List<Bean.MiaoshaBean.ListBeanX>  data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public Adapter02 onCreateViewHolder(ViewGroup parent, int viewType) {
        //視圖
        View view = View.inflate(context, R.layout.shitu02,null);
        Adapter02 adapter02 = new Adapter02(view);
        return adapter02;
    }

    @Override
    public void onBindViewHolder(Adapter02 holder, int position) {
        //找到控件之後賦值
        holder.tex1.setText(data.get(position).getTitle());
        Glide.with(context).load(data.get(position).getImages().split("\\|")[0]).into(holder.img1);
    }

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

//第四個

//名字Adapter03

public class Adapter03 extends RecyclerView.Adapter<Adapter02> {
    private List<Bean.TuijianBean.ListBean> data;
    private Context context;

    public Adapter03(List<Bean.TuijianBean.ListBean> data, Context context) {
        this.data = data;
        this.context = context;
    }


    @Override
    public Adapter02 onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.shitu03,null);
        Adapter02 adapter02 = new Adapter02(view);

        return adapter02;
    }

    @Override
    public void onBindViewHolder(Adapter02 holder, int position) {
        holder.tex2.setText(data.get(position).getTitle());
        Glide.with(context).load(data.get(position).getImages().split("\\|")[0]).into(holder.img2);
    }

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

//依賴

compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.youth.banner:banner:1.4.9'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.squareup.okio:okio:1.11.0'
testCompile 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.6.1'


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章