DrawerLayout侧滑+TabLayout横向滑动+ViewPager+轮播+PullToRefresh

主布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/draw"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.week3_moni.MainActivity">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RadioGroup
                android:id="@+id/rel_navigate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/rb_sy"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_selector"
                    android:button="@null"
                    android:checked="true"
                    android:gravity="center"
                    android:padding="3dp"
                    android:text="首页" />
                <!--rb_index-->
                <RadioButton
                    android:id="@+id/rb_fx"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_selector"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="3dp"
                    android:text="发现" />
                <!--rb_video-->
                <RadioButton
                    android:id="@+id/rb_xz"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_selector"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="3dp"
                    android:text="下载" />
                <!--rb_top-->
                <RadioButton
                    android:id="@+id/rb_wd"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@drawable/rb_selector"
                    android:button="@null"
                    android:gravity="center"
                    android:padding="3dp"
                    android:text="我的" />
                <!--rb_me-->
            </RadioGroup>

            <FrameLayout
                android:id="@+id/frag"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@id/rel_navigate"></FrameLayout>
            <!--main_content-->

        </RelativeLayout>

        <!--侧拉菜单的布局   android:layout_gravity="start"  菜单在左边  end  菜单在右边 -->
        <LinearLayout
            android:id="@+id/lin"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="#CDECFC"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="152****8083" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="去完成身份认证" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="18dp"
                    android:text="钱包"
                    android:textSize="19dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:text="行程记录"
                    android:textSize="19dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:text="好友邀请"
                    android:textSize="19dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:text="设置"
                    android:textSize="19dp" />
            </LinearLayout>
        </LinearLayout>
</android.support.v4.widget.DrawerLayout>

fragment

首页shouye_fragment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#FDFBA4">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        app:tabGravity="center"
        app:tabIndicatorColor="@color/colorAccent"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@color/colorPrimaryDark"
        app:tabTextColor="@color/colorPrimary"></android.support.design.widget.TabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v4.view.ViewPager>

</LinearLayout>
 

发现,下载,我的

<?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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24dp"
        android:text="我的页面"/>

</LinearLayout>
 
TabLayout的fragment 

推荐  tuijie_fragment

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#8CDFFB">

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="260dp"
        android:id="@+id/vp"
        android:layout_alignParentTop="true"
        ></android.support.v4.view.ViewPager>

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:id="@+id/plv"
        android:layout_below="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ptr:ptrDrawable="@drawable/default_ptr_flip"
        ptr:ptrAnimationStyle="flip"
        ptr:ptrHeaderBackground="#383838"
        ptr:ptrHeaderTextColor="#FFFFFF"></com.handmark.pulltorefresh.library.PullToRefreshListView>
</RelativeLayout>

课程,实战,职业路径

<?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"
    android:background="#D9A5FC">

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="课程"/>
</LinearLayout>

 
item_list
<?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"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/img"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher"/>
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="234"/>
</LinearLayout>
 
 
 
fragment背景颜色设置
rb_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@android:color/holo_red_dark"></item>

</selector>

ic_empty,ic_error,ic_stub
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

</selector>

 
 
MyTask
package com.example.week3_moni;
import android.os.AsyncTask;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by ass on 2017/10/21.
 */

public class MyTask extends AsyncTask<String,Void,String> {
    private Icallback icallback;
    private StringBuilder sb;

    public MyTask(Icallback icallback) {
        this.icallback = icallback;
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            URL url=new URL(params[0]);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.setReadTimeout(2000);
            urlConnection.setConnectTimeout(2000);

            if(urlConnection.getResponseCode()==200){
                InputStream inputStream = urlConnection.getInputStream();
                sb=new StringBuilder();
                String con;
                BufferedReader br=new BufferedReader(new InputStreamReader(inputStream));
                if((con=br.readLine())!=null){
                    sb.append(con);
                }

                //Log.i("----", "醉了"+sb.toString());
                return sb.toString();
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        icallback.Updatatext(s);
    }

    public interface Icallback{
        void Updatatext(String str);
    }
}

ImagePager
package com.example.week3_moni;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.week3_moni.Util.MyApplication;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by ass on 2017/10/21.
 */

public class ImagePager extends PagerAdapter{
    Context context;
    List<String> list;

    public ImagePager(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView=new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        ImageLoader.getInstance().displayImage(list.get(position%list.size()),imageView,MyApplication.getImageOptions());
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}

UtilBean

MyPagerAdapter(TabLayout的viewpager)
package com.example.week3_moni.Adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.week3_moni.Fragment.ContentFragment;
import com.example.week3_moni.TabFragment.KechengFragment;
import com.example.week3_moni.TabFragment.ShizhanFragment;
import com.example.week3_moni.TabFragment.ZhiyeFragment;

import java.util.List;

/**
 * Created by ass on 2017/10/21.
 */

public class MyPagerAdapter extends FragmentPagerAdapter{

    private List<String> tabs;

    public MyPagerAdapter(FragmentManager fm, List<String> tabs) {
        super(fm);
        this.tabs=tabs;
    }

    //用于返回选项卡的文本
    @Override
    public CharSequence getPageTitle(int position) {
        return tabs.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment frag=null;
        switch (position){
            case 0:
                frag=new ContentFragment();
                break;
            case 1:
                frag=new KechengFragment();
                break;
            case 2:
                frag=new ShizhanFragment();
                break;
            case 3:
                frag=new ZhiyeFragment();
                break;
        }
        return frag;
    }

    @Override
    public int getCount() {
        return tabs.size();
    }
}

MyApplication
package com.example.week3_moni.Util;

        import android.app.Application;
        import android.graphics.Bitmap;

        import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
        import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
        import com.nostra13.universalimageloader.core.DisplayImageOptions;
        import com.nostra13.universalimageloader.core.ImageLoader;
        import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

        import java.io.File;

/**
 * Created by ass on 2017/10/21.
 */

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        File cacheFile=getExternalCacheDir();
        ImageLoaderConfiguration config=new ImageLoaderConfiguration.Builder(this)
                .memoryCacheExtraOptions(480, 800)//缓存图片最大的长和宽
                .threadPoolSize(2)//线程池的数量
                .threadPriority(4)
                .memoryCacheSize(2*1024*1024)//设置内存缓存区大小
                .diskCacheSize(20*1024*1024)//设置sd卡缓存区大小
                .diskCache(new UnlimitedDiskCache(cacheFile))//自定义缓存目录
                .writeDebugLogs()//打印日志内容
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理
                .build();

        ImageLoader.getInstance().init(config);
    }
    public static DisplayImageOptions getImageOptions(){

        DisplayImageOptions optionsoptions=new DisplayImageOptions.Builder()
                .cacheInMemory(true)//使用内存缓存
                .cacheOnDisk(true)//使用磁盘缓存
                .bitmapConfig(Bitmap.Config.RGB_565)//设置图片格式
                .build();

        return optionsoptions;
    }
}


Fragment
ShouyeFragment
package com.example.week3_moni.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.week3_moni.Adapter.MyPagerAdapter;
import com.example.week3_moni.R;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by ass on 2017/10/21.
 */

public class ShouyeFragment extends Fragment {

    private List<String> datas=new ArrayList<>();
    private View view;
    private TabLayout tab;
    private ViewPager vp;

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

        tab = (TabLayout) view.findViewById(R.id.tab);
        vp=(ViewPager) view.findViewById(R.id.vp);

        return view;
    }

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

        datas.add("推荐");
        datas.add("课程");
        datas.add("实战");
        datas.add("职业路径");

        vp.setAdapter(new MyPagerAdapter(getChildFragmentManager(),datas));

        tab.setupWithViewPager(vp);
    }
}
FaxianFragment,XiazaiFragment,WodeFragment
package com.example.week3_moni.Fragment;

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 com.example.week3_moni.R;

/**
 * Created by ass on 2017/10/21.
 */

public class FaxianFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=View.inflate(getActivity(), R.layout.faxian_fragment,null);
        return view;
    }
}

 
TabLayoutFragment
ContentFragment
package com.example.week3_moni.Fragment;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.example.week3_moni.ImagePager;
import com.example.week3_moni.MyTask;
import com.example.week3_moni.R;
import com.example.week3_moni.UtilBean;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ass on 2017/10/21.
 */

public class ContentFragment extends Fragment implements PullToRefreshListView.OnRefreshListener2<ListView> {

    private ViewPager vp;
    private LinearLayout lin;
    private StringBuilder builder;
    private Handler myHandler = new Handler();
    private List<UtilBean.DataBean> list = new ArrayList<>();
    private List<UtilBean.DataBean> lists = new ArrayList<>();
    MyAdapter adapter;
    int type = 1;
    int index = 1;

    PullToRefreshListView pull;
    private List<String> data;
    private List<ImageView> images;
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .cacheInMemory(true)//进行内存缓存
            .cacheOnDisk(true)//进行sd卡缓存
            .showImageOnLoading(R.drawable.ic_stub) // 设置正在下载中的图片
            .showImageForEmptyUri(R.drawable.ic_empty) //没有请求地址时
            .showImageOnFail(R.drawable.ic_error)//下载错误时
            .bitmapConfig(Bitmap.Config.RGB_565)//设置图片质量
            .build();

    private Handler handler = new Handler() {

        public void handleMessage(Message msg) {
            //获取当前正在显示的页面
            int it = vp.getCurrentItem();
            vp.setCurrentItem(it + 1);
            sendEmptyMessageDelayed(0, 3000);
        }
    };

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.tuijie_fragment, container,false);
        vp = (ViewPager) view.findViewById(R.id.vp);
        lin = (LinearLayout) view.findViewById(R.id.lin);
        pull = (PullToRefreshListView) view.findViewById(R.id.plv);
        data = new ArrayList<String>();
        data.add("http://pic8.nipic.com/20100701/5290458_114840036316_2.jpg");
        data.add("http://pic2.nipic.com/20090424/1468853_230119053_2.jpg");
        data.add("http://img3.3lian.com/2013/s1/20/d/57.jpg");
        data.add("http://pic39.nipic.com/20140226/18071023_164300608000_2.jpg");
        data.add("http://a0.att.hudong.com/15/08/300218769736132194086202411_950.jpg");

        vp.setAdapter(new ImagePager(getActivity(), data));
        vp.setCurrentItem(data.size() * 10);
        handler.sendEmptyMessageDelayed(1, 2000);
        init();
        initdata();

        return view;
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
        addtoTop();
        myHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                pull.onRefreshComplete();
            }
        }, 1000);
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
        addtoBottom();
        myHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                pull.onRefreshComplete();
            }
        }, 1000);
    }

    public void initdata() {
        index = 1;
        MyTask task = new MyTask(new MyTask.Icallback() {
            @Override
            public void Updatatext(String str) {
                Log.i("---", "---"+str);
                Gson gson = new Gson();
                UtilBean u = gson.fromJson(str, UtilBean.class);
                list = u.getData();
                lists.addAll(list);
                Log.d("zzz","*******"+lists.size());

                setAdapter();
            }
        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);
    }

    public void addtoTop() {
        index = 1;
        MyTask task = new MyTask(new MyTask.Icallback() {
            @Override
            public void Updatatext(String str) {
                Gson gson = new Gson();
                UtilBean u = gson.fromJson(str, UtilBean.class);
                list = u.getData();
                lists.addAll(0,list);
            }
        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);
    }

    public void addtoBottom() {
        index++;
        MyTask task = new MyTask(new MyTask.Icallback() {
            @Override
            public void Updatatext(String str) {
                Gson gson = new Gson();
                UtilBean u = gson.fromJson(str, UtilBean.class);
                list = u.getData();
                lists.addAll(list);
            }
        });
        task.execute("http://api.expoon.com/AppNews/getNewsList/type/1/p/"+index);
    }

    public void init() {
        //设置刷新模式 ,both代表支持上拉和下拉,pull_from_end代表上拉,pull_from_start代表下拉
        pull.setMode(PullToRefreshBase.Mode.BOTH);


/*这里通过getLoadingLayoutProxy 方法来指定上拉和下拉时显示的状态的区别,第一个true 代表下来状态 ,第二个true 代表上拉的状态
如果想区分上拉和下拉状态的不同,可以分别设置*/

        ILoadingLayout startLabels = pull.getLoadingLayoutProxy(true, false);
        startLabels.setPullLabel("下拉刷新");
        startLabels.setRefreshingLabel("正在拉");
        startLabels.setReleaseLabel("放开刷新");

        ILoadingLayout endLabels = pull.getLoadingLayoutProxy(false, true);
        endLabels.setPullLabel("上拉刷新");
        endLabels.setRefreshingLabel("正在载入...");
        endLabels.setReleaseLabel("放开刷新...");

        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {//下拉刷新的回调
                //下拉刷新的数据,显示在listview列表的最上面
                addtoTop();
                myHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //刷新完成,必须在异步下完成
                        pull.onRefreshComplete();
                        //刷新适配器
                        setAdapter();
                    }
                }, 1000);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {//上拉加载的回调
                //加载更多的数据,添加到集合列表的最后面
                addtoBottom();
                myHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //刷新完成,必须在异步下完成
                        pull.onRefreshComplete();
                        //刷新适配器
                        setAdapter();
                    }
                }, 1000);
            }
        });
    }

    public void setAdapter() {
        if (adapter == null){
            adapter = new MyAdapter();
            pull.setAdapter(adapter);
            Log.d("zzz","*****setadapterlvlvlvlvlvlv****");

        } else {
            adapter.notifyDataSetChanged();
        }
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return lists.size();
        }

        @Override
        public Object getItem(int position) {
            return lists.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder vh;
            if (convertView == null) {
                convertView = View.inflate(getActivity(), R.layout.item_list, null);
                vh = new ViewHolder();
                vh.img = (ImageView) convertView.findViewById(R.id.img);
                vh.tv = (TextView) convertView.findViewById(R.id.tv);
                convertView.setTag(vh);
            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            Log.d("00000","(((("+lists.get(position).getNews_title());
            vh.tv.setText(lists.get(position).getNews_title());

            //第三步:进行加载显示
            ImageLoader.getInstance().displayImage(lists.get(position).getPic_url(), vh.img, options);
            return convertView;
        }
        class ViewHolder {
            ImageView img;
            TextView tv;
        }
    }
}
 
 
 
kechengFragment,shizhanFragment,ZhiyeFragment
package com.example.week3_moni.TabFragment;

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 com.example.week3_moni.R;

/**
 * Created by ass on 2017/10/21.
 */

public class ShizhanFragment extends Fragment{
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=View.inflate(getActivity(), R.layout.shizhan_fragment,null);
        return view;
    }
}
 

MainActivity

package com.example.week3_moni;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import com.example.week3_moni.Fragment.FaxianFragment;
import com.example.week3_moni.Fragment.ShouyeFragment;
import com.example.week3_moni.Fragment.WodeFragment;
import com.example.week3_moni.Fragment.XiazaiFragment;

public class MainActivity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private LinearLayout lin;
    private DrawerLayout draw;
    private ImageView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        draw = (DrawerLayout) findViewById(R.id.draw);
        img = (ImageView) findViewById(R.id.img);
        radioGroup = (RadioGroup) findViewById(R.id.rel_navigate);

        //侧滑菜单的视图
        lin = (LinearLayout) findViewById(R.id.lin);

        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //关闭,侧滑菜单
                draw.closeDrawer(lin);
            }
        });

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId==R.id.rb_sy){
                    addFragment(new ShouyeFragment());
                }else if(checkedId==R.id.rb_fx){
                    addFragment(new FaxianFragment());

                }else if(checkedId==R.id.rb_xz){
                    addFragment(new XiazaiFragment());

                }else if(checkedId==R.id.rb_wd){
                    addFragment(new WodeFragment());
                }
            }
        });
        addFragment(new ShouyeFragment());
    }

    /**
     * 添加fragment到主页面中
     * @param fragment
     */
    public  void addFragment(Fragment fragment){
        getSupportFragmentManager().beginTransaction().replace(R.id.frag,fragment).commit();
    }
}

(注:)最后在清单文件内设置网络权限


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值