Class MainActivity:
package animtest.com.example.e531.yuekao_test_demo;
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 animtest.com.example.e531.yuekao_test_demo.fragments.IndexFragment;
import animtest.com.example.e531.yuekao_test_demo.fragments.MeFragment;
import animtest.com.example.e531.yuekao_test_demo.fragments.TopFragment;
import animtest.com.example.e531.yuekao_test_demo.fragments.VideoFragment;
public class MainActivity extends AppCompatActivity {
private ImageView imgTitle;
private RelativeLayout relMenu;
private DrawerLayout drawerLayout;
private RadioGroup radioGroup;
@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.img_title);
radioGroup = (RadioGroup) findViewById(R.id.rel_navigate);
//侧滑菜单的视图
relMenu = (RelativeLayout) findViewById(R.id.rel_menu);
imgTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//关闭,侧滑菜单
drawerLayout.closeDrawer(relMenu);
}
});
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId==R.id.rb_index){
Log.d("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());
}
/**
* 添加fragment到主页面中
* @param fragment
*/
public void addFragment(Fragment fragment){
getSupportFragmentManager().beginTransaction().replace(R.id.main_content,fragment).commit();
}
}
Class MyApplication:
package animtest.com.example.e531.yuekao_test_demo;
import android.app.Application;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import java.io.File;
/**
* Created by e531 on 2017/10/14.
*/
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 UnlimitedDiscCache(cacheFile))//自定义缓存目录
.writeDebugLogs()//打印日志内容
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理
.build();
ImageLoader.getInstance().init(config);
}
}
Class MyTask:
package animtest.com.example.e531.yuekao_test_demo.Utils;
import android.os.AsyncTask;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/**
* 使用AsyncTask+HttpURLConnection请求数据
* Created by e531 on 2017/10/12.
*/
public class MyTask extends AsyncTask<String,Void,String> {
//申请一个接口类对象
private Icallbacks icallbacks;
//将无参构造设置成私有的,使之在外部不能够调用
private MyTask(){}
//定义有参构造方法
public MyTask(Icallbacks icallbacks) {
this.icallbacks = icallbacks;
}
@Override
protected String doInBackground(String... params) {
String str="";
try {
//使用HttpUrlConnection
URL url=new URL(params[0]);
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
if(connection.getResponseCode()==200){
InputStream inputStream=connection.getInputStream();
//调用工具类中的静态方法
str=StreamToString.streamToStr(inputStream,"utf-8");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
return str;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
//解析,封装到bean,更新ui组件
icallbacks.updateUiByjson(s);
}
//定义一个接口
public interface Icallbacks{
/**
* 根据回传的json字符串,解析并更新页面组件
* @param jsonstr
*/
void updateUiByjson(String jsonstr);
}
}
Class StreamToString:
package animtest.com.example.e531.yuekao_test_demo.Utils;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
/**
* Created by e531 on 2017/10/12.
*/
public class StreamToString {
public static String streamToStr(InputStream inputStream,String chartSet){
StringBuilder builder=new StringBuilder();
try {
BufferedReader br=new BufferedReader(new InputStreamReader(inputStream,chartSet));
String con;
while ((con=br.readLine())!=null){
builder.append(con);
}
br.close();
return builder.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
Class MeFragment:
package animtest.com.example.e531.yuekao_test_demo.fragments;
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 animtest.com.example.e531.yuekao_test_demo.R;
/**
* Created by e531 on 2017/10/14.
*/
public class MeFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.me_layout,null);
return v;
}
}
Class IndexFragment:
package animtest.com.example.e531.yuekao_test_demo.fragments;
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.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
import animtest.com.example.e531.yuekao_test_demo.Bean.TabModel;
import animtest.com.example.e531.yuekao_test_demo.R;
/**
* Created by e531 on 2017/10/14
*
*/
public class IndexFragment extends Fragment {
private ViewPager viewPager;
private TabLayout tabLayout;
private List<TabModel> lists=new ArrayList<TabModel>();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.index_layout,null);
viewPager = (ViewPager) v.findViewById(R.id.vp);
tabLayout = (TabLayout) v.findViewById(R.id.mytab);
//tab标题信息
intTabData();
//设置适配器 ,,得到子fragment的管理者,使用getChildFragmentManager
viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
//建立关联
tabLayout.setupWithViewPager(viewPager);
//指定加载的页数 http://blog.csdn.net/qq_29134495/article/details/51548002
viewPager.setOffscreenPageLimit(lists.size());
return v;
}
/**
* 初使化tab导航
*/
private void intTabData() {
lists.add(new TabModel("数据新闻","xbsjxw"));
lists.add(new TabModel("快讯","txs"));
lists.add(new TabModel("头条","toutiao"));
lists.add(new TabModel("精编公告","news/mobile/jbgg"));
lists.add(new TabModel("美股","news/mobile/mgxw"));
lists.add(new TabModel("港股","news/mobile/ggxw"));
lists.add(new TabModel("基金","news/mobile/jjxw"));
lists.add(new TabModel("理财","news/mobile/lcxw"));
}
class MyAdapter extends FragmentPagerAdapter{
public MyAdapter(FragmentManager fm) {
super(fm);
}
//获取tab导航文本
@Override
public CharSequence getPageTitle(int position) {
return lists.get(position).getTitle();
}
@Override
public Fragment getItem(int position) {
Log.d("zzz","pager adapter ***********"+position);
Bundle bundle=new Bundle();
bundle.putString("dataType",lists.get(position).getType());
bundle.putString("pageIndex","1");
ContentFragment contentFragment=new ContentFragment();
contentFragment.setArguments(bundle);
return contentFragment;
}
@Override
public int getCount() {
return lists.size();
}
}
}
Class ContentFragment:
package animtest.com.example.e531.yuekao_test_demo.fragments;
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.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import animtest.com.example.e531.yuekao_test_demo.Bean.Result;
import animtest.com.example.e531.yuekao_test_demo.R;
import animtest.com.example.e531.yuekao_test_demo.Utils.MyTask;
import animtest.com.example.e531.yuekao_test_demo.adapter.MyAdapter;
import animtest.com.example.e531.yuekao_test_demo.view.XListView;
/**
* Created by e531 on 2017/10/14.
*/
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<>();
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.Icallbacks() {
@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);
}
}
Class TopFragment:
package animtest.com.example.e531.yuekao_test_demo.fragments;
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 animtest.com.example.e531.yuekao_test_demo.R;
/**
* Created by e531 on 2017/10/14.
*/
public class TopFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.top_layout,null);
return v;
}
}
Class VideoFragment:
package animtest.com.example.e531.yuekao_test_demo.fragments;
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 animtest.com.example.e531.yuekao_test_demo.R;
/**
* Created by e531 on 2017/10/14.
*/
public class VideoFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.video_layout,null);
return v;
}
}
Class Result:
package animtest.com.example.e531.yuekao_test_demo.Bean;
import java.util.List;
/**
* Created by e531 on 2017/10/14.
*/
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;
}
}
}
Class TabModel:
package animtest.com.example.e531.yuekao_test_demo.Bean;
/**
* Created by e531 on 2017/10/14.
*/
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 void setTitle(String title) {
this.title = title;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Class MyAdapter:
package animtest.com.example.e531.yuekao_test_demo.adapter;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
import animtest.com.example.e531.yuekao_test_demo.Bean.Result;
import animtest.com.example.e531.yuekao_test_demo.R;
/**
* Created by e531 on 2017/10/14.
*/
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;
}
}
Class XListView:
/**
* @file XListView.java
* @package me.maxwin.view
* @create Mar 18, 2012 6:28:41 PM
* @author Maxwin
* @description An ListView support (a) Pull down to refresh, (b) Pull up to load more.
* Implement IXListViewListener, and see stopRefresh() / stopLoadMore().
*/
package animtest.com.example.e531.yuekao_test_demo.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.animation.DecelerateInterpolator;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Scroller;
import android.widget.TextView;
import animtest.com.example.e531.yuekao_test_demo.R;
public class XListView extends ListView implements OnScrollListener {
private float mLastY = -1; // save event y
private Scroller mScroller; // used for scroll back
private OnScrollListener mScrollListener; // user's scroll listener
// the interface to trigger refresh and load more.
private IXListViewListener mListViewListener;
// -- header view
private XListViewHeader mHeaderView;
// header view content, use it to calculate the Header's height. And hide it
// when disable pull refresh.
private RelativeLayout mHeaderViewContent;
private TextView mHeaderTimeView;
private int mHeaderViewHeight; // header view's height
private boolean mEnablePullRefresh = true;
private boolean mPullRefreshing = false; // is refreashing.
// -- footer view
private XListViewFooter mFooterView;
private boolean mEnablePullLoad;
private boolean mPullLoading;
private boolean mIsFooterReady = false;
// total list items, used to detect is at the bottom of listview.
private int mTotalItemCount;
// for mScroller, scroll back from header or footer.
private int mScrollBack;
private final static int SCROLLBACK_HEADER = 0;
private final static int SCROLLBACK_FOOTER = 1;
private final static int SCROLL_DURATION = 400; // scroll back duration
private final static int PULL_LOAD_MORE_DELTA = 50; // when pull up >= 50px
// at bottom, trigger
// load more.
private final static float OFFSET_RADIO = 1.8f; // support iOS like pull
// feature.
/**
* @param context
*/
public XListView(Context context) {
super(context);
initWithContext(context);
}
public XListView(Context context, AttributeSet attrs) {
super(context, attrs);
initWithContext(context);
}
public XListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initWithContext(context);
}
private void initWithContext(Context context) {
mScroller = new Scroller(context, new DecelerateInterpolator());
// XListView need the scroll event, and it will dispatch the event to
// user's listener (as a proxy).
super.setOnScrollListener(this);
// init header view
mHeaderView = new XListViewHeader(context);
mHeaderViewContent = (RelativeLayout) mHeaderView
.findViewById(R.id.xlistview_header_content);
mHeaderTimeView = (TextView) mHeaderView
.findViewById(R.id.xlistview_header_time);
addHeaderView(mHeaderView);
// init footer view
mFooterView = new XListViewFooter(context);
// init header height
mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mHeaderViewHeight = mHeaderViewContent.getHeight();
getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
});
}
@Override
public void setAdapter(ListAdapter adapter) {
// make sure XListViewFooter is the last footer view, and only add once.
if (mIsFooterReady == false) {
mIsFooterReady = true;
addFooterView(mFooterView);
}
super.setAdapter(adapter);
}
/**
* enable or disable pull down refresh feature.
*
* @param enable
*/
public void setPullRefreshEnable(boolean enable) {
mEnablePullRefresh = enable;
if (!mEnablePullRefresh) { // disable, hide the content
mHeaderViewContent.setVisibility(View.INVISIBLE);
} else {
mHeaderViewContent.setVisibility(View.VISIBLE);
}
}
/**
* enable or disable pull up load more feature.
*
* @param enable
*/
public void setPullLoadEnable(boolean enable) {
mEnablePullLoad = enable;
if (!mEnablePullLoad) {
mFooterView.hide();
mFooterView.setOnClickListener(null);
//make sure "pull up" don't show a line in bottom when listview with one page
setFooterDividersEnabled(false);
} else {
mPullLoading = false;
mFooterView.show();
mFooterView.setState(XListViewFooter.STATE_NORMAL);
//make sure "pull up" don't show a line in bottom when listview with one page
setFooterDividersEnabled(true);
// both "pull up" and "click" will invoke load more.
mFooterView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startLoadMore();
}
});
}
}
/**
* stop refresh, reset header view.
*/
public void stopRefresh() {
if (mPullRefreshing == true) {
mPullRefreshing = false;
resetHeaderHeight();
}
}
/**
* stop load more, reset footer view.
*/
public void stopLoadMore() {
if (mPullLoading == true) {
mPullLoading = false;
mFooterView.setState(XListViewFooter.STATE_NORMAL);
}
}
/**
* set last refresh time
*
* @param time
*/
public void setRefreshTime(String time) {
mHeaderTimeView.setText(time);
}
private void invokeOnScrolling() {
if (mScrollListener instanceof OnXScrollListener) {
OnXScrollListener l = (OnXScrollListener) mScrollListener;
l.onXScrolling(this);
}
}
private void updateHeaderHeight(float delta) {
mHeaderView.setVisiableHeight((int) delta
+ mHeaderView.getVisiableHeight());
if (mEnablePullRefresh && !mPullRefreshing) { // 未处于刷新状态,更新箭头
if (mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
mHeaderView.setState(XListViewHeader.STATE_READY);
} else {
mHeaderView.setState(XListViewHeader.STATE_NORMAL);
}
}
setSelection(0); // scroll to top each time
}
/**
* reset header view's height.
*/
private void resetHeaderHeight() {
int height = mHeaderView.getVisiableHeight();
if (height == 0) // not visible.
return;
// refreshing and header isn't shown fully. do nothing.
if (mPullRefreshing && height <= mHeaderViewHeight) {
return;
}
int finalHeight = 0; // default: scroll back to dismiss header.
// is refreshing, just scroll back to show all the header.
if (mPullRefreshing && height > mHeaderViewHeight) {
finalHeight = mHeaderViewHeight;
}
mScrollBack = SCROLLBACK_HEADER;
mScroller.startScroll(0, height, 0, finalHeight - height,
SCROLL_DURATION);
// trigger computeScroll
invalidate();
}
private void updateFooterHeight(float delta) {
int height = mFooterView.getBottomMargin() + (int) delta;
if (mEnablePullLoad && !mPullLoading) {
if (height > PULL_LOAD_MORE_DELTA) { // height enough to invoke load
// more.
mFooterView.setState(XListViewFooter.STATE_READY);
} else {
mFooterView.setState(XListViewFooter.STATE_NORMAL);
}
}
mFooterView.setBottomMargin(height);
// setSelection(mTotalItemCount - 1); // scroll to bottom
}
private void resetFooterHeight() {
int bottomMargin = mFooterView.getBottomMargin();
if (bottomMargin > 0) {
mScrollBack = SCROLLBACK_FOOTER;
mScroller.startScroll(0, bottomMargin, 0, -bottomMargin,
SCROLL_DURATION);
invalidate();
}
}
private void startLoadMore() {
mPullLoading = true;
mFooterView.setState(XListViewFooter.STATE_LOADING);
if (mListViewListener != null) {
mListViewListener.onLoadMore();
}
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mLastY == -1) {
mLastY = ev.getRawY();
}
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastY = ev.getRawY();
break;
case MotionEvent.ACTION_MOVE:
final float deltaY = ev.getRawY() - mLastY;
mLastY = ev.getRawY();
if (getFirstVisiblePosition() == 0
&& (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
// the first item is showing, header has shown or pull down.
updateHeaderHeight(deltaY / OFFSET_RADIO);
invokeOnScrolling();
} else if (getLastVisiblePosition() == mTotalItemCount - 1
&& (mFooterView.getBottomMargin() > 0 || deltaY < 0)) {
// last item, already pulled up or want to pull up.
updateFooterHeight(-deltaY / OFFSET_RADIO);
}
break;
default:
mLastY = -1; // reset
if (getFirstVisiblePosition() == 0) {
// invoke refresh
if (mEnablePullRefresh
&& mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
mPullRefreshing = true;
mHeaderView.setState(XListViewHeader.STATE_REFRESHING);
if (mListViewListener != null) {
mListViewListener.onRefresh();
}
}
resetHeaderHeight();
} else if (getLastVisiblePosition() == mTotalItemCount - 1) {
// invoke load more.
if (mEnablePullLoad
&& mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA
&& !mPullLoading) {
startLoadMore();
}
resetFooterHeight();
}
break;
}
return super.onTouchEvent(ev);
}
@Override
public void computeScroll() {
if (mScroller.computeScrollOffset()) {
if (mScrollBack == SCROLLBACK_HEADER) {
mHeaderView.setVisiableHeight(mScroller.getCurrY());
} else {
mFooterView.setBottomMargin(mScroller.getCurrY());
}
postInvalidate();
invokeOnScrolling();
}
super.computeScroll();
}
@Override
public void setOnScrollListener(OnScrollListener l) {
mScrollListener = l;
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (mScrollListener != null) {
mScrollListener.onScrollStateChanged(view, scrollState);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// send to user's listener
mTotalItemCount = totalItemCount;
if (mScrollListener != null) {
mScrollListener.onScroll(view, firstVisibleItem, visibleItemCount,
totalItemCount);
}
}
public void setXListViewListener(IXListViewListener l) {
mListViewListener = l;
}
/**
* you can listen ListView.OnScrollListener or this one. it will invoke
* onXScrolling when header/footer scroll back.
*/
public interface OnXScrollListener extends OnScrollListener {
public void onXScrolling(View view);
}
/**
* implements this interface to get refresh/load more event.
*/
public interface IXListViewListener {
public void onRefresh();
public void onLoadMore();
}
}
Class XListViewFooter:
/**
* @file XFooterView.java
* @create Mar 31, 2012 9:33:43 PM
* @author Maxwin
* @description XListView's footer
*/
package animtest.com.example.e531.yuekao_test_demo.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import animtest.com.example.e531.yuekao_test_demo.R;
public class XListViewFooter extends LinearLayout {
public final static int STATE_NORMAL = 0;
public final static int STATE_READY = 1;
public final static int STATE_LOADING = 2;
private Context mContext;
private View mContentView;
private View mProgressBar;
private TextView mHintView;
public XListViewFooter(Context context) {
super(context);
initView(context);
}
public XListViewFooter(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public void setState(int state) {
mHintView.setVisibility(View.INVISIBLE);
mProgressBar.setVisibility(View.INVISIBLE);
mHintView.setVisibility(View.INVISIBLE);
if (state == STATE_READY) {
mHintView.setVisibility(View.VISIBLE);
mHintView.setText(R.string.xlistview_footer_hint_ready);
} else if (state == STATE_LOADING) {
mProgressBar.setVisibility(View.VISIBLE);
} else {
mHintView.setVisibility(View.VISIBLE);
mHintView.setText(R.string.xlistview_footer_hint_normal);
}
}
public void setBottomMargin(int height) {
if (height < 0) return ;
LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
lp.bottomMargin = height;
mContentView.setLayoutParams(lp);
}
public int getBottomMargin() {
LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
return lp.bottomMargin;
}
/**
* normal status
*/
public void normal() {
mHintView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
/**
* loading status
*/
public void loading() {
mHintView.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
/**
* hide footer when disable pull load more
*/
public void hide() {
LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
lp.height = 0;
mContentView.setLayoutParams(lp);
}
/**
* show footer
*/
public void show() {
LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
lp.height = LayoutParams.WRAP_CONTENT;
mContentView.setLayoutParams(lp);
}
private void initView(Context context) {
mContext = context;
LinearLayout moreView = (LinearLayout)LayoutInflater.from(mContext).inflate(R.layout.xlistview_footer, null);
addView(moreView);
moreView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mContentView = moreView.findViewById(R.id.xlistview_footer_content);
mProgressBar = moreView.findViewById(R.id.xlistview_footer_progressbar);
mHintView = (TextView)moreView.findViewById(R.id.xlistview_footer_hint_textview);
}
}
XListViewHeader:
/**
* @file XListViewHeader.java
* @create Apr 18, 2012 5:22:27 PM
* @author Maxwin
* @description XListView's header
*/
package animtest.com.example.e531.yuekao_test_demo.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import animtest.com.example.e531.yuekao_test_demo.R;
public class XListViewHeader extends LinearLayout {
private LinearLayout mContainer;
private ImageView mArrowImageView;
private ProgressBar mProgressBar;
private TextView mHintTextView;
private int mState = STATE_NORMAL;
private Animation mRotateUpAnim;
private Animation mRotateDownAnim;
private final int ROTATE_ANIM_DURATION = 180;
public final static int STATE_NORMAL = 0;
public final static int STATE_READY = 1;
public final static int STATE_REFRESHING = 2;
public XListViewHeader(Context context) {
super(context);
initView(context);
}
/**
* @param context
* @param attrs
*/
public XListViewHeader(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
private void initView(Context context) {
// 初始情况,设置下拉刷新view高度为0
LayoutParams lp = new LayoutParams(
LayoutParams.FILL_PARENT, 0);
mContainer = (LinearLayout) LayoutInflater.from(context).inflate(
R.layout.xlistview_header, null);
addView(mContainer, lp);
setGravity(Gravity.BOTTOM);
mArrowImageView = (ImageView)findViewById(R.id.xlistview_header_arrow);
mHintTextView = (TextView)findViewById(R.id.xlistview_header_hint_textview);
mProgressBar = (ProgressBar)findViewById(R.id.xlistview_header_progressbar);
mRotateUpAnim = new RotateAnimation(0.0f, -180.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION);
mRotateUpAnim.setFillAfter(true);
mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION);
mRotateDownAnim.setFillAfter(true);
}
public void setState(int state) {
if (state == mState) return ;
if (state == STATE_REFRESHING) { // 显示进度
mArrowImageView.clearAnimation();
mArrowImageView.setVisibility(View.INVISIBLE);
mProgressBar.setVisibility(View.VISIBLE);
} else { // 显示箭头图片
mArrowImageView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.INVISIBLE);
}
switch(state){
case STATE_NORMAL:
if (mState == STATE_READY) {
mArrowImageView.startAnimation(mRotateDownAnim);
}
if (mState == STATE_REFRESHING) {
mArrowImageView.clearAnimation();
}
mHintTextView.setText(R.string.xlistview_header_hint_normal);
break;
case STATE_READY:
if (mState != STATE_READY) {
mArrowImageView.clearAnimation();
mArrowImageView.startAnimation(mRotateUpAnim);
mHintTextView.setText(R.string.xlistview_header_hint_ready);
}
break;
case STATE_REFRESHING:
mHintTextView.setText(R.string.xlistview_header_hint_loading);
break;
default:
}
mState = state;
}
public void setVisiableHeight(int height) {
if (height < 0)
height = 0;
LayoutParams lp = (LayoutParams) mContainer
.getLayoutParams();
lp.height = height;
mContainer.setLayoutParams(lp);
}
public int getVisiableHeight() {
return mContainer.getLayoutParams().height;
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="animtest.com.example.e531.yuekao_test_demo.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:id="@+id/rel_navigate"
android:layout_alignParentBottom="true">
<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:background="@drawable/rb_selector"
android:checked="true"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="视频"
android:button="@null"
android:padding="3dp"
android:gravity="center"
android:id="@+id/rb_video"
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:padding="3dp"
android:id="@+id/rb_top"
android:background="@drawable/rb_selector"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="我的"
android:padding="3dp"
android:button="@null"
android:gravity="center"
android:id="@+id/rb_me"
android:background="@drawable/rb_selector"/>
</RadioGroup>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/rel_navigate"
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/img_title"
android:layout_marginBottom="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是侧边栏"
android:layout_below="@+id/img_title"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
content_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<animtest.com.example.e531.yuekao_test_demo.view.XListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/xlv">
</animtest.com.example.e531.yuekao_test_demo.view.XListView>
</LinearLayout>
index_layout.xml:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vp"></android.support.v4.view.ViewPager>
</LinearLayout>
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" 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:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tv"
android:text="这是我页面"
android:textColor="#f00"
/>
</LinearLayout>
top_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tv"
android:text="这是头条页面"
android:textColor="#f00"
/>
</LinearLayout>
video_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tv"
android:text="这是视频页面"
android:textColor="#f00"
/>
</LinearLayout>
xlistview_footer.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/xlistview_footer_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<ProgressBar
android:id="@+id/xlistview_footer_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
<TextView
android:id="@+id/xlistview_footer_hint_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/xlistview_footer_hint_normal" />
</RelativeLayout>
</LinearLayout>
xlistview_header.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom" >
<RelativeLayout
android:id="@+id/xlistview_header_content"
android:layout_width="fill_parent"
android:layout_height="60dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" android:id="@+id/xlistview_header_text">
<TextView
android:id="@+id/xlistview_header_hint_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xlistview_header_hint_normal" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xlistview_header_last_time"
android:textSize="12sp" />
<TextView
android:id="@+id/xlistview_header_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/xlistview_header_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/xlistview_header_text"
android:layout_centerVertical="true"
android:layout_marginLeft="-35dp"
android:src="@drawable/xlistview_arrow" />
<ProgressBar
android:id="@+id/xlistview_header_progressbar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignLeft="@id/xlistview_header_text"
android:layout_centerVertical="true"
android:layout_marginLeft="-40dp"
android:visibility="invisible" />
</RelativeLayout>
</LinearLayout>
drawable-->rb_selector.xml:
<?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>
values-->strings.xml:
<resources>
<string name="app_name">XListView</string>
<string name="xlistview_header_hint_normal">下拉刷新</string>
<string name="xlistview_header_hint_ready">松开刷新数据</string>
<string name="xlistview_header_hint_loading">正在加载...</string>
<string name="xlistview_header_last_time">上次更新时间:</string>
<string name="xlistview_footer_hint_normal">查看更多</string>
<string name="xlistview_footer_hint_ready">松开载入更多</string>
</resources>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="animtest.com.example.e531.yuekao_test_demo">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".MyApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".MyApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>