当前位置:   article > 正文

Fragment隐藏显示与DrawerLayout侧拉 Banner与PullToRefreshListView 和 Banner与xlistview分类加载数据_drawerlayout fragment 数据刷新

drawerlayout fragment 数据刷新
//工具类
public class Utils {
    public static String getNetString(String str){
            try {
                URL url=new URL(str);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                int responseCode = urlConnection.getResponseCode();
                if (responseCode==200){
                    InputStream is = urlConnection.getInputStream();
                    BufferedReader br=new BufferedReader(new InputStreamReader(is));
                    StringBuilder sb=new StringBuilder();
                    String line=null;
                    while ((line=br.readLine())!=null){
                        sb.append(line);
                    }
                    return sb.toString();
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public static DisplayImageOptions getDisplayImageOption() {
                DisplayImageOptions options = new DisplayImageOptions.Builder()
                        .showImageOnLoading(R.mipmap.ic_launcher) //设置图片在下载期间显示的图片
                        .showImageForEmptyUri(R.mipmap.ic_launcher)//设置图片Uri为空或是错误的时候显示的图片
                        .showImageOnFail(R.mipmap.ic_launcher)  //设置图片加载/解码过程中错误时候显示的图片
                        .cacheInMemory(true)//设置下载的图片是否缓存在内存中
                        .cacheOnDisk(true)
                        .considerExifParams(true)  //是否考虑JPEG图像EXIF参数(旋转,翻转)
                        .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//设置图片以如何的编码方式显示
                        .bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型//
                        .displayer(new RoundedBitmapDisplayer(30))//是否设置为圆角,弧度为多少
                       // .displayer(new FadeInBitmapDisplayer(100))//是否图片加载好后渐入的动画时间
                 //.displayer(new CircleBitmapDisplayer())//显示圆形图片
                        .build();
              //构建完成
                      return options;
              }

    /**
     * 返回值 -1:没有网络  1:WIFI网络   2:net网络
     //工具类 判断网络
     */
               public static int getNetype(Context context) {
                       int netType = -1;
                       ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                       NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
                       if (networkInfo == null) {
                           return netType;
                       }
                       int nType = networkInfo.getType();
                       if (nType == ConnectivityManager.TYPE_MOBILE) {
                           netType = 2;
                       } else if (nType == ConnectivityManager.TYPE_WIFI) {
                           netType = 1;
                       }
                       return netType;
                   }

 
 //modle的buil.gradle文件中android根标签下   添加useLibrary 'org.apache.http.legacy'
    public static String getJsonByHttpClientGet(String jsonUrl) {
        //获取httpclient对象
        DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
        //准备一个get请求
//        HttpGet httpGet = new HttpGet(jsonUrl);
        HttpPost httpPost = new HttpPost(jsonUrl);
        try {
            //得到服务器返回的数据;
            HttpResponse response = defaultHttpClient.execute(httpPost);
            //得到状态码
            int statusCode = response.getStatusLine().getStatusCode();
            if(statusCode ==200){
                //entiry 里面封装的数据;
                HttpEntity entity = response.getEntity();
                //这个result就是json字符串,剩下的就是解析工作了;
                // String result = EntityUtils.toString(entity);
                return EntityUtils.toString(entity);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
 
//初始化ImageLoader图片框架
 
public class MApp extends Application{
     //继承Application
      File cacheFile= new File(Environment.getExternalStorageDirectory()+"/"+"imgages");

         @Override
         public void onCreate() {
             super.onCreate();
             //初始化组件,链式开发思想,整个框架的参数初始化配置
             ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this)
                     .memoryCacheExtraOptions(480, 800) // default = device screen dimensions 内存缓存文件的最大长宽
                     .diskCacheExtraOptions(480, 800, null)  // 本地缓存的详细信息(缓存的最大长宽),最好不要设置这个
                     .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                     .denyCacheImageMultipleSizesInMemory()
                     .threadPoolSize(3)
                     .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) //可以通过自己的内存缓存实现
                     .memoryCacheSize(2 * 1024 * 1024)  // 内存缓存的最大值
                     .memoryCacheSizePercentage(13) // default
                     .diskCacheSize(50 * 1024 * 1024) // 50 Mb sd卡(本地)缓存的最大值
                     .diskCacheFileCount(100)  // 可以缓存的文件数量
                     .diskCache(new UnlimitedDiskCache(cacheFile))//自定义缓存目录
                      // .threadPoolSize(3)//设置线程数
                     // default为使用HASHCODE对UIL进行加密命名, 还可以用MD5(new Md5FileNameGenerator())加密
                     .diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
                     .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
                     .writeDebugLogs() // 打印debug log
                     .build();

             ImageLoader.getInstance().init(configuration);

         }
}

//Fragment隐藏显示 DrawerLayout侧拉
 
public class MainActivity extends AppCompatActivity {

    private RadioGroup rg;
    private FragmentManager manager;
    private MainFragment1 mfragment1;
    private MainFragment2 mfragment2;
    private MainFragment3 mfragment3;
    private MainFragment4 mfragment4;
    private DrawerLayout drawerLayout;
    private LinearLayout mlayout;
    private ListView lv;
    private List<String> list=new ArrayList<String>();
    @Override
      protected void onResume() {
          super.onResume();
          int netype = Utils.getNetype(MainActivity.this);
          if (netype == -1) {
              Toast.makeText(this, "当前网络异常,请做联网操作!", Toast.LENGTH_SHORT).show();
          } else if (netype == 1) {
              Toast.makeText(this, "当前网络正常,正在使用WiFi网络", Toast.LENGTH_SHORT).show();
          } else if (netype == 0) {
              Toast.makeText(this, "当前网络正常,正在使用运营商网络(3G/4G),请注意流量的使用", Toast.LENGTH_SHORT).show();
          }
      }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        manager = getSupportFragmentManager();
        initData();
        rg = (RadioGroup) findViewById(R.id.main_rg);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        mlayout = (LinearLayout) findViewById(R.id.mlayout);
        lv = (ListView) findViewById(R.id.main_lv);
        mfragment1 = new MainFragment1();
        manager.beginTransaction().add(R.id.main_fl,mfragment1).commit();
        rg.setOnCheckedChangeListener(new Moccl());
        lv.setAdapter(new MAdapter());
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                drawerLayout.closeDrawer(mlayout);
            }
        });
    }

    private void initData() {
        list.add("掌上宝");
        list.add("应用宝");
        list.add("蚂蚁凭租");
        list.add("掌上营业部");
    }

    private class Moccl implements RadioGroup.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            hideFragments();
             switch (i){
                         case R.id.main_rb1:
                             manager.beginTransaction().show(mfragment1).commit();
                             break;
                         case R.id.main_rb2:
                             if (mfragment2==null){
                                 mfragment2 = new MainFragment2();
                                 manager.beginTransaction().add(R.id.main_fl,mfragment2).commit();
                             }else{
                                 manager.beginTransaction().show(mfragment2).commit();
                             }
                             break;
                             case R.id.main_rb3:
                             if (mfragment3==null){
                                 mfragment3 = new MainFragment3();
                                 manager.beginTransaction().add(R.id.main_fl,mfragment3).commit();
                             }else{
                                 manager.beginTransaction().show(mfragment3).commit();
                             }
                             break;
                             case R.id.main_rb4:
                             if (mfragment4==null){
                                 mfragment4 = new MainFragment4();
                                 manager.beginTransaction().add(R.id.main_fl,mfragment4).commit();
                             }else{
                                 manager.beginTransaction().show(mfragment4).commit();
                             }
                             break;
                     }
        }
    }

    private void hideFragments() {
        if (mfragment1!=null&&mfragment1.isAdded()){
            manager.beginTransaction().hide(mfragment1).commit();
                    }
        if (mfragment2!=null&&mfragment2.isAdded()){
            manager.beginTransaction().hide(mfragment2).commit();
                    }
        if (mfragment3!=null&&mfragment3.isAdded()){
            manager.beginTransaction().hide(mfragment3).commit();
                    }
        if (mfragment4!=null&&mfragment4.isAdded()){
            manager.beginTransaction().hide(mfragment4).commit();
                    }
    }

    private class MAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

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

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view==null){
                view = View.inflate(MainActivity.this, R.layout.mainlist_item, null);
            }
            TextView tv = view.findViewById(R.id.main_item_tv);
            tv.setText(list.get(i));
            return view;
        }
    }
}

 
//ViewPager加载Fragment布局
 
public class MainFragment1 extends Fragment {

    private ViewPager vp;
    private List<Fragment> list=new ArrayList<Fragment>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mainfragment1, container, false);
        vp = view.findViewById(R.id.child_vp);
        initData();
        return view;
    }

    private void initData() {
        list.add(new ChildFragment1());
        list.add(new ChildFragment2());
        list.add(new ChildFragment3());
        list.add(new ChildFragment4());
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        vp.setAdapter(new MyAdapter(getChildFragmentManager()));
    }

    private class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }
        @Override
        public int getCount() {
            return list.size();
        }
    }
}

//TabLayout和ViewPager加载页面
 
public class MainFragment2 extends Fragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> fragmentList=new ArrayList<Fragment>();
    private List<String> tilteList=new ArrayList<String>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mainfragment2, container, false);
        tabLayout = view.findViewById(R.id.tabLayout);
        viewPager = view.findViewById(R.id.viewPager);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
        viewPager.setAdapter(new MPagerAdapter(getChildFragmentManager()));
	//与viewpager联动
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setupWithViewPager(viewPager);
    }
//添加数据
    private void initData() {
        fragmentList.add(new ChildFrag1());
        fragmentList.add(new ChildFrag2());
        fragmentList.add(new ChildFrag3());
        fragmentList.add(new ChildFrag4());
        tilteList.add("水");
        tilteList.add("火");
        tilteList.add("光");
        tilteList.add("暗");
    }
    class MPagerAdapter extends FragmentPagerAdapter{

        public MPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }
		//必须重写getPageTitle()方法

        @Override
        public CharSequence getPageTitle(int position) {
            return tilteList.get(position);
        }
    }
}

//Banner 与 PullToRefreshListView
//Banner 通过子线程解析接口 发送到Handler实现图片轮播
//PullToRefreshListView 网络获取数据 实现上拉加载 下拉刷新

public class ChildFragment1 extends Fragment {
    private String NetString="http://api.expoon.com/AppNews/getNewsList/type/1/p/1";
    private String ImageNetString="http://www.93.gov.cn/93app/data.do?channelId=0&startNum=";
    private Banner banner;
    private int count=0;
    private PullToRefreshListView pull;
    List<NetBean.DataBean> list=new ArrayList<NetBean.DataBean>();
    private Handler handler=new Handler(){

        @Override
        public void handleMessage(Message msg) {
            int what = msg.what;
             switch (what){
                         case 1:
                             List<TextBean.DataBean> data = (List<TextBean.DataBean>) msg.obj;
                             List<String> images = new ArrayList<String>();
                             List<String> titles = new ArrayList<String>();
                                    for (int i=0;i<data.size();i++){
                                        images.add(data.get(i).getPic_url());
                                        titles.add(data.get(i).getNews_title());
                                    }
                                    banner.setImageLoader(new BImageLoader());
                                    banner.setImages(images);
                                     banner.setBannerTitles(titles);
                                     banner.start();
                             break;
                     }
        }
    };
    private com.nostra13.universalimageloader.core.ImageLoader instance;
    private MAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.childfragment1, container, false);
        pull = view.findViewById(R.id.pullToRefresh);
        View inflate = View.inflate(getContext(), R.layout.hanner, null);
         banner = inflate.findViewById(R.id.banner);
        pull.getRefreshableView().addHeaderView(inflate);
        instance = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        getHandlerMsg();
        getNetData(count);
        mAdapter = new MAdapter();
        pull.setAdapter(mAdapter);
        pull.setMode(PullToRefreshBase.Mode.BOTH);
        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                list.clear();;
                getNetData(count);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                getNetData(count++);
            }
        });
    }

    public void getNetData(int count) {
        new MAsyncTask().execute(ImageNetString+count);
    }
        class MAsyncTask extends AsyncTask<String,Void,String>{

            @Override
            protected String doInBackground(String... strings) {
                return Utils.getNetString(strings[0]);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                Gson gson=new Gson();
                NetBean json = gson.fromJson(s, NetBean.class);
                List<NetBean.DataBean> beans = json.getData();
                list.addAll(beans);
                mAdapter.notifyDataSetChanged();
                pull.onRefreshComplete();
            }
        }
    class BImageLoader extends ImageLoader{
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            com.nostra13.universalimageloader.core.ImageLoader instance = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
            instance.displayImage((String) path,imageView);
        }
    }

    private void getHandlerMsg() {
        new Thread(){
            @Override
            public void run() {
                String str = Utils.getNetString(NetString);
                Gson gson=new Gson();
                TextBean json = gson.fromJson(str, TextBean.class);
                List<TextBean.DataBean> data = json.getData();
                Message msg=new Message();
                msg.obj=data;
                msg.what=1;
                handler.sendMessage(msg);
            }
        }.start();
    }
    private class MAdapter extends BaseAdapter {

        private TextView TITLE;
        private TextView SUBTITLE;
        private ImageView IMAGEURL;
        private TextView FROMNAME;
        private ViewHolder vh;
        private VHolder vholder;

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

        @Override
        public Object getItem(int i) {
            return null;
        }

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

        @Override
        public int getItemViewType(int position) {
            //根据图片是否为空进行判断
            int flag=0;
            if (list.get(position).getIMAGEURL()==null&&list.get(position).getIMAGEURL()==""){
                flag=0;
            }else if (list.get(position).getIMAGEURL()!=null&&list.get(position).getIMAGEURL()!=""){
                flag=1;
            }
            return flag;
        }

        @Override
        public int getViewTypeCount() {
            //getview里有几个布局就写几
            return 2;
        }


        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            int type = getItemViewType(i);
            switch (type){
                case 0:
                    if (view==null){
                        vholder = new VHolder();
                        view = View.inflate(getActivity(), R.layout.titem, null);
                        view.setTag(vholder);
                    }else{
                        vholder = (VHolder) view.getTag();
                    }
                    vholder.TITLE = view.findViewById(R.id.item_TITLE);
                    vholder.SUBTITLE = view.findViewById(R.id.item_SUBTITLE);
                    vholder.FROMNAME = view.findViewById(R.id.item_FROMNAME);
                    vholder.TITLE.setText(list.get(i).getTITLE());
                    vholder.SUBTITLE.setText(list.get(i).getSUBTITLE());
                    vholder.FROMNAME.setText(list.get(i).getFROMNAME());
                    break;
                case 1:
                    if (view==null){
                        vh = new ViewHolder();
                        view = View.inflate(getActivity(), R.layout.item, null);
                        view.setTag(vh);
                    }else{
                        vh = (ViewHolder) view.getTag();
                    }
                    vh.TITLE = view.findViewById(R.id.item_TITLE);
                    vh.SUBTITLE = view.findViewById(R.id.item_SUBTITLE);
                    vh.IMAGEURL = view.findViewById(R.id.item_IMAGEURL);
                    vh.FROMNAME = view.findViewById(R.id.item_FROMNAME);
                    vh.TITLE.setText(list.get(i).getTITLE());
                    vh.SUBTITLE.setText(list.get(i).getSUBTITLE());
                    vh.FROMNAME.setText(list.get(i).getFROMNAME());
                    instance.displayImage(list.get(i).getIMAGEURL(),vh.IMAGEURL,Utils.getDisplayImageOption());
                    break;
            }
            return view;
        }
    }
    class ViewHolder{
        TextView TITLE;
        TextView SUBTITLE;
        ImageView IMAGEURL;
        TextView FROMNAME;
    } class VHolder{
        TextView TITLE;
        TextView SUBTITLE;
        TextView FROMNAME;
    }
}

 
//Banner图片轮播 xlistview加载数据 实现上下拉功能
 
public class ChildFragment2 extends Fragment implements XListView.IXListViewListener{
    private int num=1;
    private String NetString="http://api.expoon.com/AppNews/getNewsList/type/2/p/";
    private String BannerString="http://api.expoon.com/AppNews/getNewsList/type/1/p/2";
    private XListView xlistview;
    List<NewsBean.DataBean> list=new ArrayList<NewsBean.DataBean>();
    private XlViewAdapter mmadapter;
    private com.nostra13.universalimageloader.core.ImageLoader instance;
    private Banner banner;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.childfragment2, container, false);
        instance = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
        xlistview = view.findViewById(R.id.child2_xlv);
        View child_banner = View.inflate(getActivity(), R.layout.hanner, null);
         banner = child_banner.findViewById(R.id.banner);
        xlistview.addHeaderView(child_banner);
        //banner = view.findViewById(R.id.child2_banner);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        getHandleMsgNet();
        getData(num);
        mmadapter = new XlViewAdapter();
        xlistview.setAdapter(mmadapter);
        xlistview.setPullLoadEnable(true);
        xlistview.setXListViewListener(this);
    }
class BannerImageLoader extends ImageLoader {

    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        com.nostra13.universalimageloader.core.ImageLoader instance = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
        instance.displayImage((String) path,imageView);
    }
}
    public void getData(int num) {
        new MyAsyncTask().execute(NetString+num);
    }

    @Override
    public void onRefresh() {
        num=0;
        list.clear();
        getData(num);
    }

    @Override
    public void onLoadMore() {
        getData(num++);
        list.clear();
    }
    private void uiComplete(){
        xlistview.stopRefresh();
        xlistview.stopLoadMore();
        xlistview.setRefreshTime("就不告诉你!!!");
    }

    public void getHandleMsgNet() {
        new BannerAsyncTask().execute(BannerString);
    }
    class BannerAsyncTask extends AsyncTask<String,Void,String>{
        @Override
        protected String doInBackground(String... strings) {
            return Utils.getNetString(strings[0]);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            Gson gson = new Gson();
            NewsBean beans = gson.fromJson(s, NewsBean.class);
            List<NewsBean.DataBean> data = beans.getData();
            List<String> images=new ArrayList<String>();
            List<String> titles=new ArrayList<String>();
            for (int i=0;i<data.size();i++){
                images.add(data.get(i).getPic_url());
                titles.add(data.get(i).getNews_title());
            }
            banner.setImageLoader(new BannerImageLoader());
            banner.setImages(images);
            banner.setBannerTitles(titles);
            banner.start();
        }
    }
    class MyAsyncTask extends AsyncTask<String,Void,String>{
         @Override
         protected String doInBackground(String... strings) {
             return Utils.getNetString(strings[0]);
         }

         @Override
         protected void onPostExecute(String s) {
             super.onPostExecute(s);
             Gson gson = new Gson();
             NewsBean beans = gson.fromJson(s, NewsBean.class);
             List<NewsBean.DataBean> data = beans.getData();
             list.addAll(data);
             mmadapter.notifyDataSetChanged();
             uiComplete();
         }
     }
     class XlViewAdapter extends BaseAdapter{

         private TextView id;
         private TextView summary;
         private TextView title;
         private ImageView pic_url;
         private ViewHolder vholder;

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

         @Override
         public Object getItem(int i) {
             return null;
         }

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

         @Override
         public View getView(int i, View view, ViewGroup viewGroup) {
             if (view==null){
                 vholder = new ViewHolder();
                 view = View.inflate(getActivity(), R.layout.xlistviewitem, null);
                 view.setTag(vholder);
             }else{
                  vholder = (ViewHolder) view.getTag();
             }
             vholder.id = view.findViewById(R.id.xlistviewitem_news_id);
             vholder.summary = view.findViewById(R.id.xlistviewitem_news_summary);
             vholder.title = view.findViewById(R.id.xlistviewitem_news_title);
             vholder.pic_url = view.findViewById(R.id.xlistviewitem_pic_url);
             vholder.id.setText(list.get(i).getNews_id());
             vholder.summary.setText(list.get(i).getNews_summary());
             vholder.title.setText(list.get(i).getNews_title());
             instance.displayImage(list.get(i).getPic_url(), vholder.pic_url,Utils.getDisplayImageOption());
             return view;
         }
     }
     class ViewHolder{
          TextView id;
          TextView summary;
          TextView title;
          ImageView pic_url;
     }
}

//main布局
<?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/drawerLayout"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ljn.myapplication.MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/main_fl"
        ></FrameLayout>
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/main_rg"
    >
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:button="@null"
        android:text="首页"
        android:background="@drawable/selected"
        android:gravity="center_horizontal"
        android:id="@+id/main_rb1"
        />
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:button="@null"
        android:text="猜"
        android:background="@drawable/selected"
        android:gravity="center_horizontal"
        android:id="@+id/main_rb2"
        />
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:button="@null"
        android:text="淘"
        android:background="@drawable/selected"
        android:gravity="center_horizontal"
        android:id="@+id/main_rb3"
        />
    <RadioButton
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:button="@null"
        android:text="我的"
        android:background="@drawable/selected"
        android:gravity="center_horizontal"
        android:id="@+id/main_rb4"
        />
</RadioGroup>
</LinearLayout>
    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:id="@+id/mlayout"
        android:orientation="vertical"
	//实现侧拉
        android:layout_gravity="left"
        android:choiceMode="singleChoice"
        android:background="@color/DarkOrchid"
        >
    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/p"
        android:layout_gravity="center_horizontal"
        />
        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/main_lv"
            ></ListView>
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

//TabLayout 和 ViewPager的xml布局
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

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

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pullToRefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

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

<com.bwie.xlistviewlibrary.View.XListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/child2_xlv"
    ></com.bwie.xlistviewlibrary.View.XListView>
</LinearLayout>

 
//Banner 的布局
 
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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/banner"
        android:layout_width="match_parent"
        android:layout_height="200dp">
    </com.youth.banner.Banner>
</android.support.constraint.ConstraintLayout>

 

在清单文件中配置

//网络状态
<uses-permission android:name="android.permission.INTERNET" />
//sd读写权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
//判断wifi状态
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


在application中配置
android:name=".Mapp"
在build.grable下配置
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'  //ImageLoader依赖
compile 'com.google.code.gson:gson:2.2.4' //Gson依赖
compile 'com.youth.banner:banner:1.4.9' //Banner依赖
implementation project(':PullToRefreshLibrary')//导入PullToRefreshLibrary工程 实现上下滑动数据更新
implementation project(':xlistviewlibrary')//导入xListview工程 上下上下滑动数据更新
compile'com.android.support:design:26+' //TabLayout的依赖


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/279667
推荐阅读
相关标签
  

闽ICP备14008679号