//main方法
import android.support.annotation.IdRes; import android.support.v4.app.Fragment; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.RadioGroup; import android.widget.RelativeLayout; import com.example.yuekaoshang.Fragment.IndexFragment; import com.example.yuekaoshang.Fragment.MeFragment; import com.example.yuekaoshang.Fragment.TopFragment; import com.example.yuekaoshang.Fragment.VideoFragment; public class MainActivity extends AppCompatActivity { private DrawerLayout drawerLayout; private ImageView imgTitle; private RadioGroup radioGroup; private RelativeLayout reMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerLayout = (DrawerLayout) findViewById(R.id.mydrawer); imgTitle = (ImageView) findViewById(R.id.image_title); radioGroup = (RadioGroup) findViewById(R.id.rel_navtigate); //侧滑菜单视图 reMenu = (RelativeLayout) findViewById(R.id.rel_menu); imgTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //关闭菜单 drawerLayout.closeDrawer(reMenu); } }); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { if(checkedId==R.id.rb_index){ Log.i("zzz","add index fragment ***********"); addFragment(new IndexFragment()); }else if(checkedId==R.id.rb_top){ addFragment(new TopFragment()); }else if(checkedId==R.id.rb_me){ addFragment(new MeFragment()); }else if(checkedId==R.id.rb_video){ addFragment(new VideoFragment()); } } }); //默认加载页面 addFragment(new IndexFragment()); } public void addFragment(Fragment fragment){ getSupportFragmentManager().beginTransaction().replace(R.id.main_content,fragment).commit(); } }
//适配器
public class MyAdapter extends BaseAdapter{ private List<Result.DataEntity> datas; private Context context; private DisplayImageOptions options; public MyAdapter(List<Result.DataEntity> datas, Context context) { this.datas = datas; this.context = context; options=new DisplayImageOptions.Builder() .cacheInMemory(true)//使用内存缓存 .cacheOnDisk(true)//使用磁盘缓存 .bitmapConfig(Bitmap.Config.RGB_565)//设置图片格式 .build(); } @Override public int getCount() { return datas.size(); } @Override public Object getItem(int position) { return datas.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if(convertView==null){ convertView=View.inflate(context, R.layout.item,null); holder=new ViewHolder(); holder.tvTitle= (TextView) convertView.findViewById(R.id.tv_title); holder.img= (ImageView) convertView.findViewById(R.id.img); convertView.setTag(holder); }else{ holder=(ViewHolder) convertView.getTag(); } holder.tvTitle.setText(datas.get(position).getTitle()); if(datas.get(position).getImg()==null || datas.get(position).getImg().equals("")){ holder.img.setImageResource(R.mipmap.ic_launcher); }else{ //imageLoader加载图片 ImageLoader.getInstance().displayImage(datas.get(position).getImg(),holder.img,options); } return convertView; } class ViewHolder{ TextView tvTitle; ImageView img; } }
//Bean包解析数据
public class Result { /** * data : [{"summary":"10月11日,A股两融余额达到9946.47亿元,距万亿关口仅一步之遥。而A股最近一次向上突破万亿元大关的时间是2014年12月24日,当日两融余额为10018","id":"236923","title":"时隔34个月两融余额再逼万亿 场外配资复燃难掩牛市分歧","otime":"2017-10-13 07:20:49","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236923.json","resType":"","countid":20035},{"summary":"资金流向方面,昨日沪深两市共有918个上市公司获得资金净流入,环比减少171家,另有2258家公司遭遇资金净流出,环比增加174家,全天累计有223.19亿元资","id":"236909","title":"轮动提速板块分化 \u201c游击战\u201d成资金主流","otime":"2017-10-13 06:36:49","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236909.json","resType":"","countid":20035},{"summary":"10月为上市公司三季报披露月。初步统计,节后至今共有28家公司披露股东、高管等减持计划。其中,深沪主板共11家,创业板、中小板分别有10家、7家。","id":"236911","title":"节后28家公司发布股东减持计划","otime":"2017-10-13 07:02:32","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236911.json","resType":"","countid":20035},{"summary":"","id":"236910","title":"沪股通净流出4.07亿元 深股通净流入8.94亿元","otime":"2017-10-13 06:46:46","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236910.json","resType":"","countid":20035},{"summary":"统计数据显示,截至10月10日,两融余额为9925.82亿元,连续两个交易日快速增加,较国庆节前增加230.84亿元。与此同时,上证指数也在节后一度攻破3400","id":"236783","title":"两融余额再度逼近万亿 电子行业受青睐","otime":"2017-10-12 06:43:56","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236783.json","resType":"","countid":20035},{"summary":"据西南证券统计数据显示,8月份根据上市公司公告计算的限售股解禁后减持市值为38.85亿元,涉及上市公司157家,共计26555.40万股。9月份公告的限售股解禁","id":"236781","title":"密集减持只是\u201c假象\u201d 产业资本分歧显现","otime":"2017-10-12 06:41:29","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236781.json","resType":"","countid":20035},{"summary":"","id":"236657","title":"沪股通净流入24.65亿元 深股通净流入17.54亿元","otime":"2017-10-11 06:49:18","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236657.json","resType":"","countid":20035},{"summary":"今年下半年以来,券商佣金收入已连续三个月正增长,三季度共实现佣金收入244亿元,相当于今年上半年佣金收入的61%。总体来看,券商经纪业务收入或为三季度业绩增添色","id":"236655","title":"券商第三季度佣金稳赚244亿元 收入连续三个月攀升","otime":"2017-10-11 06:43:19","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236655.json","resType":"","countid":20035},{"summary":"据统计,8月份根据上市公司公告计算的限售股解禁后减持市值为38.85亿元,涉及上市公司157家,共计26555.40万股。8月份上市公司股份获得增持市值共计66","id":"236654","title":"9月份减持市值环比骤增 增持市值翻倍","otime":"2017-10-11 06:41:08","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236654.json","resType":"","countid":20035},{"summary":"截至10月9日,沪深两融余额再度回到9800亿元上方,达9858.72亿元,处于近期较高水平。","id":"236653","title":"两融重登9800亿上方 市场韧性依然较强","otime":"2017-10-11 06:38:43","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236653.json","resType":"","countid":20035},{"summary":"","id":"236559","title":"A股逾千家公司年内买理财产品 累计金额达1.11万亿元","otime":"2017-10-10 09:13:02","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236559.json","resType":"","countid":20035},{"summary":"","id":"236516","title":"沪股通净流入47.15亿元 深股通净流入29.68亿元","otime":"2017-10-10 06:51:50","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236516.json","resType":"","countid":20035},{"summary":"据数据统计,目前创业板共有131家公司披露了前三季度的业绩预报,其中,有40家公司预测净利润同比将有超过100%的增长幅度(按预告净利润最大变动幅度这一指标排序","id":"236512","title":"40家创业板公司预计前三季业绩翻番","otime":"2017-10-10 06:47:00","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236512.json","resType":"","countid":20035},{"summary":"受\u201c双节\u201d假期因素影响,9月下旬两融市场谨慎情绪弥漫,9月21日-29日,沪深两市融资余额连续\u201c七连跌\u201d,累计净流出金额为273.68亿元。其中,仅9月29日当","id":"236510","title":"融资净偿还创近8个月单日新高","otime":"2017-10-10 06:43:27","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236510.json","resType":"","countid":20035},{"summary":"数据显示,截至10月9日中国证券报记者发稿时,1330家A股公司发布三季报业绩预告。其中,预喜公司1003家,占比为75%,有346家公司预计净利润同比增长50","id":"236509","title":"逾千家公司三季报业绩预喜","otime":"2017-10-10 06:42:22","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236509.json","resType":"","countid":20035},{"summary":"","id":"236411","title":"两市融资余额在节前最后一日减少148亿","otime":"2017-10-09 08:57:07","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236411.json","resType":"","countid":20035},{"summary":"根据沪深交易所的安排,本周沪深两市共有56家公司的限售股解禁上市流通,解禁股数共计109.08亿股,占未解禁限售A股的1.28%。其中,沪市56.73亿股,占沪","id":"236400","title":"本周56家上市公司解禁市值达1042亿元","otime":"2017-10-09 08:04:55","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236400.json","resType":"","countid":20035},{"summary":"","id":"236388","title":"1285公司预告前三季业绩 230家增幅翻倍","otime":"2017-10-09 07:00:54","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236388.json","resType":"","countid":20035},{"summary":"","id":"236083","title":"融资客节前撤退 两市融资余额6连降","otime":"2017-09-29 09:09:06","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/09/236083.json","resType":"","countid":20035},{"summary":"","id":"236041","title":"沪股通净流出1.58亿元 深股通净流出1.38亿元","otime":"2017-09-29 06:52:59","source":"","views":"","img":"","advTypeShare":"","url":"http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/09/236041.json","resType":"","countid":20035}] * header : {"pagesize":20,"last":"page_10.json","pre":"page_1.json","next":"page_2.json","totalsize":200,"totalpage":10,"first":"page_1.json"} */ private List<DataEntity> data; private HeaderEntity header; public void setData(List<DataEntity> data) { this.data = data; } public void setHeader(HeaderEntity header) { this.header = header; } public List<DataEntity> getData() { return data; } public HeaderEntity getHeader() { return header; } public class DataEntity { /** * summary : 10月11日,A股两融余额达到9946.47亿元,距万亿关口仅一步之遥。而A股最近一次向上突破万亿元大关的时间是2014年12月24日,当日两融余额为10018 * id : 236923 * title : 时隔34个月两融余额再逼万亿 场外配资复燃难掩牛市分歧 * otime : 2017-10-13 07:20:49 * source : * views : * img : * advTypeShare : * url : http://mnews.gw.com.cn/wap/data/news/xbsjxw/2017/10/236923.json * resType : * countid : 20035 */ private String summary; private String id; private String title; private String otime; private String source; private String views; private String img; private String advTypeShare; private String url; private String resType; private int countid; public void setSummary(String summary) { this.summary = summary; } public void setId(String id) { this.id = id; } public void setTitle(String title) { this.title = title; } public void setOtime(String otime) { this.otime = otime; } public void setSource(String source) { this.source = source; } public void setViews(String views) { this.views = views; } public void setImg(String img) { this.img = img; } public void setAdvTypeShare(String advTypeShare) { this.advTypeShare = advTypeShare; } public void setUrl(String url) { this.url = url; } public void setResType(String resType) { this.resType = resType; } public void setCountid(int countid) { this.countid = countid; } public String getSummary() { return summary; } public String getId() { return id; } public String getTitle() { return title; } public String getOtime() { return otime; } public String getSource() { return source; } public String getViews() { return views; } public String getImg() { return img; } public String getAdvTypeShare() { return advTypeShare; } public String getUrl() { return url; } public String getResType() { return resType; } public int getCountid() { return countid; } } public class HeaderEntity { /** * pagesize : 20 * last : page_10.json * pre : page_1.json * next : page_2.json * totalsize : 200 * totalpage : 10 * first : page_1.json */ private int pagesize; private String last; private String pre; private String next; private int totalsize; private int totalpage; private String first; public void setPagesize(int pagesize) { this.pagesize = pagesize; } public void setLast(String last) { this.last = last; } public void setPre(String pre) { this.pre = pre; } public void setNext(String next) { this.next = next; } public void setTotalsize(int totalsize) { this.totalsize = totalsize; } public void setTotalpage(int totalpage) { this.totalpage = totalpage; } public void setFirst(String first) { this.first = first; } public int getPagesize() { return pagesize; } public String getLast() { return last; } public String getPre() { return pre; } public String getNext() { return next; } public int getTotalsize() { return totalsize; } public int getTotalpage() { return totalpage; } public String getFirst() { return first; } } }
//Bean 的封装
public class TabModel { private String title; private String type; public TabModel(String title, String type) { this.title = title; this.type = type; } public String getTitle() { return title; } public String getType() { return type; } public void setTitle(String title) { this.title = title; } public void setType(String type) { this.type = type; } }
//工具包
public class MyTask extends AsyncTask<String,Void,String> { //申请一个接口类对象 private Icallback icallback; //将无参构造设置成私有的,使之在外部不能够调用 public MyTask(){} //定义有参构造方法 public MyTask(Icallback icallback) { this.icallback = icallback; } @Override protected String doInBackground(String... params) { String str=""; try { URL url=new URL(params[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setReadTimeout(3000); connection.setConnectTimeout(3000); if(connection.getResponseCode()==200){ InputStream inputStream = connection.getInputStream(); //调用工具类中的静态方法 str=StreamToString.streamTost(inputStream,"utf-8"); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return str; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); icallback.updateUiByjson(s); } //定一个接口 public interface Icallback{ void updateUiByjson(String jsonstr); } }
//工具包
public class StreamToString { public static String streamTost(InputStream inputStream,String charSet) { StringBuilder builder = new StringBuilder(); try { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charSet)); String con; while ((con = br.readLine()) != null) { builder.append(con); } br.close(); return builder.toString(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; } }
//调用工具包
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); } }
//Fragment
public class ContentFragment extends Fragment implements XListView.IXListViewListener{ //扩展的listivew private XListView xListView; //分类标识 private String dataType; //第几页 private int pageIndex; //请求的数据url private String requestUrl=""; private MyAdapter adapter; private List<Result.DataEntity> datas=new ArrayList<Result.DataEntity>(); private int refeshType=1; private Handler myHandler=new Handler(){ @Override public void handleMessage(Message msg) { if(msg.what==1){ xListView.stopRefresh();//关闭 //设置时间 SimpleDateFormat simpleDateFormat=new SimpleDateFormat("HH:ss"); String time=simpleDateFormat.format(new Date(System.currentTimeMillis())); xListView.setRefreshTime(time); }else{ xListView.stopLoadMore(); } } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view=View.inflate(getActivity(), R.layout.content_layout,null); xListView = (XListView) view.findViewById(R.id.xlv); //设置支持下拉刷新上拉加载 xListView.setPullLoadEnable(true); // xListView.setPullLoadEnable(true); //设置接口 xListView.setXListViewListener(this); //得到传过来的参数 Bundle bundle=getArguments(); if(bundle!=null){ dataType=bundle.getString("dataType"); pageIndex=Integer.parseInt(bundle.getString("pageIndex")); //拼接请求的地址 requestUrl="http://mnews.gw.com.cn/wap/data/news/"+dataType+"/page_"+pageIndex+".json"; Log.d("zzz","&&&&"+requestUrl); } requestNetData(); return view; } /** * 进行网络数据的请求 */ private void requestNetData(){ if(!requestUrl.equals("")){ MyTask myTask=new MyTask(new MyTask.Icallback() { @Override public void updateUiByjson(String jsonstr) { Log.d("zzz","&&&&"+jsonstr); //进行解析 List<Result> results=new ArrayList<>(); Type type=new TypeToken<List<Result>>(){}.getType(); Gson gson=new Gson(); results=gson.fromJson(jsonstr,type); //得到要显示的数据 if(refeshType==1){ datas.addAll(results.get(0).getData()); }else if(refeshType==2){ datas.addAll(0,results.get(0).getData()); } //设置适配器 setAdapter(); } }); myTask.execute(requestUrl); } } /** * 设置适配器 */ public void setAdapter(){ if(adapter==null){ adapter=new MyAdapter(datas,getActivity()); xListView.setAdapter(adapter); }else{ adapter.notifyDataSetChanged(); } } //刷新 @Override public void onRefresh() { refeshType=2; pageIndex++; requestUrl="http://mnews.gw.com.cn/wap/data/news/"+dataType+"/page_"+pageIndex+".json"; requestNetData(); myHandler.sendEmptyMessageDelayed(1,1000); } @Override public void onLoadMore() { refeshType=1; pageIndex++; requestUrl="http://mnews.gw.com.cn/wap/data/news/"+dataType+"/page_"+pageIndex+".json"; requestNetData(); myHandler.sendEmptyMessageDelayed(2,1000); } }
//Fragment
public class IndexFragment extends Fragment{ private ViewPager viewPager; private List<TabModel> list=new ArrayList<TabModel>(); private TabLayout tabLayout; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.index_layout, null); viewPager = (ViewPager) inflate.findViewById(R.id.vp); tabLayout = (TabLayout) inflate.findViewById(R.id.mytab); //tab标题信息 intTabData(); //设置适配器,,得到子Fragment的管理者使用使用 getChildFragmentManager viewPager.setAdapter(new MyAdapter(getChildFragmentManager())); //建立关联 tabLayout.setupWithViewPager(viewPager); //指定加载的页数 viewPager.setOffscreenPageLimit(list.size()); return inflate; } private void intTabData() { list.add(new TabModel("数据新闻","xbsjxw")); list.add(new TabModel("快讯","txs")); list.add(new TabModel("头条","toutiao")); list.add(new TabModel("美股","news/mobile/mgxw")); list.add(new TabModel("港股","news/mobile/ggxw")); list.add(new TabModel("基金","news/mobile/jjxw")); list.add(new TabModel("理财","news/mobile/lcxw")); } class MyAdapter extends FragmentPagerAdapter{ public MyAdapter(FragmentManager fm) { super(fm); } @Override public CharSequence getPageTitle(int position) { return list.get(position).getTitle(); } @Override public Fragment getItem(int position) { Log.i("zzz","pager adapter ***********"+position); Bundle bundle=new Bundle(); bundle.putString("dataType",list.get(position).getType()); bundle.putString("pageIndex","1"); ContentFragment contentFragment=new ContentFragment(); contentFragment.setArguments(bundle); return contentFragment; } @Override public int getCount() { return list.size(); } } }
//Fragment
public class MeFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.me_layout, null); return inflate; } }
//Fragment
public class TopFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.top_layout, null); return inflate; } }
//Fragment
public class VideoFragment extends Fragment{ @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.video_layout, null); return inflate; } }
//radiaGroup设置选中颜色
<?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> <item android:drawable="@android:color/holo_blue_dark"></item> </selector>
//activity-main
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.yuekaoshang.MainActivity"> <android.support.v4.widget.DrawerLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/mydrawer" > <!--主内容区--> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true" android:id="@+id/rel_navtigate" > <RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="首页" android:button="@null" android:gravity="center" android:id="@+id/rb_index" android:padding="3dp" android:checked="true" android:background="@drawable/rb_selector" /> <RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="视频" android:button="@null" android:gravity="center" android:id="@+id/rb_video" android:padding="3dp" android:background="@drawable/rb_selector" /> <RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="微头条" android:button="@null" android:gravity="center" android:id="@+id/rb_top" android:padding="3dp" android:background="@drawable/rb_selector" /> <RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="我的" android:button="@null" android:gravity="center" android:id="@+id/rb_me" android:padding="3dp" android:background="@drawable/rb_selector" /> </RadioGroup> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/rel_navtigate" android:id="@+id/main_content" ></FrameLayout> </RelativeLayout> <RelativeLayout android:layout_width="260dp" android:layout_height="match_parent" android:id="@+id/rel_menu" android:layout_gravity="start" android:background="#550000ff" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" android:id="@+id/image_title" android:layout_marginBottom="50dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这是侧边栏" android:layout_below="@+id/image_title" /> </RelativeLayout> </android.support.v4.widget.DrawerLayout> </RelativeLayout>
//content_layout
<?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"> <com.example.yuekaoshang.view.XListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/xlv" ></com.example.yuekaoshang.view.XListView> </LinearLayout>
//index_layout
<?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" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/edit" android:layout_width="280dp" android:layout_height="wrap_content" android:hint="请输入搜索的内容" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点点" /> </LinearLayout> <android.support.design.widget.TabLayout 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:id="@+id/mytab" ></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>
//item
<?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"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/img" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv_title" /> </LinearLayout>
//me_layout
<?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="match_parent" android:layout_height="match_parent" android:id="@+id/tv" android:text="这是我页面" android:textColor="#f00" /> </LinearLayout>
//top_layout
<?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="match_parent" android:layout_height="match_parent" android:id="@+id/tv" android:text="这是头条页面" android:textColor="#f00" /> </LinearLayout>
//video_layout
<?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="match_parent" android:layout_height="match_parent" android:id="@+id/tv" android:text="这是视频页面" android:textColor="#f00" /> </LinearLayout>
//要加的权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
android:name=".MyApplication"
//还有要导入XListView-Android-master 里面的文件