mImageList = new ArrayList<ImageView>();
for (int i = 0; i < imageResIDs.length; i++) {
ImageView image = new ImageView(this);
image.setBackgroundResource(imageResIDs[i]);// 注意设置背景, 才可以填充屏幕
mImageList.add(image);
}
}
public class HomePager extends BasePager {
public HomePager(Activity activity) {
super(activity);
}
@Override
public void initData() {
tvTitle.setText("智慧北京");
btnMenu.setVisibility(View.GONE);
TextView tvContent = new TextView(mActivity);
tvContent.setText("首页");
tvContent.setTextColor(Color.RED);
tvContent.setTextSize(25);
tvContent.setGravity(Gravity.CENTER);
Gson gson = new Gson();
NewsBean news = gson.fromJson(result, NewsBean.class);
- 新闻中心对象的创建
/**
* 封装新闻中心的对象
*
* 注意: 参数起名一定要和json中的命名一致, 否则gson无法解析
*
* @author Kevin
*
*/
public class NewsBean {
public ArrayList<NewsMenuBean> data;
public ArrayList<String> extend;
public int retcode;
public class NewsMenuBean {
public ArrayList<NewsMenuTab> children;
public String id;
public String title;
public int type;
public String url;
public String url1;
@Override
public String toString() {
return "NewsMenuBean [children=" + children + ", title=" + title
+ "]";
}
}
public class NewsMenuTab {
public String id;
public String title;
public int type;
public String url;
@Override
public String toString() {
return "NewsMenuTab [id=" + id + ", title=" + title + "]";
}
}
@Override
public String toString() {
return "NewsBean [data=" + data + ", retcode=" + retcode + "]";
}
}
/**
* 页签数据封装
*
* @author Kevin
*
*/
public class TabDetailBean {
public int retcode;
public TabDatailData data;
public class TabDatailData {
public String countcommenturl;
public String more;
public ArrayList<News> news;
public String title;
public ArrayList<Topic> topic;
public ArrayList<TopNews> topnews;
/**
* 新闻列表
*
* @author Kevin
*
*/
public class News {
public String comment;
public String commentlist;
public String commenturl;
public String id;
public String listimage;
public String pubdate;
public String title;
public String type;
public String url;
@Override
public String toString() {
return "News [title=" + title + "]";
}
}
public class Topic {
public String description;
public String id;
public String listimage;
public String sort;
public String title;
public String url;
}
/**
* 顶部新闻条
*
* @author Kevin
*
*/
public class TopNews {
public String comment;
public String commentlist;
public String commenturl;
public String id;
public String topimage;
public String pubdate;
public String title;
public String type;
public String url;
@Override
public String toString() {
return "TopNews [topimage=" + topimage + ", title=" + title + "]";
}
}
@Override
public String toString() {
return "TabDetailBean [data=" + data + "]";
}
}
- 缓存处理
- 数据展示
- 顶部新闻数据展示(轮播条)
- ViewPager适配器
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView image = new ImageView(mActivity);
image.setScaleType(ScaleType.FIT_XY);//设置图片展现样式为: 宽高填充ImageView(图片可能被拉伸或者缩放)
image.setImageResource(R.drawable.topnews_item_default);
container.addView(image);
public static final int PULL_DOWN_REFRESH = 1;// 下拉刷新
public static final int RELEASE_REFRESH = 2;// 松开刷新
public static final int REFRESHING = 3;// 正在刷新
// 设置单选对话框
builder.setSingleChoiceItems(items, mSelectedSizeIndex,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d(TAG, "选中:" + which);
mCurrentSizeIndex = which;
}
});
builder.setTitle("字体设置");// 设置标题
builder.setPositiveButton("确定", new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (mCurrentSizeIndex) {
case 0:
mWebView.getSettings().setTextSize(TextSize.LARGEST);// 设置WebView中字体的大小
break;
case 1:
mWebView.getSettings().setTextSize(TextSize.LARGER);
break;
case 2:
mWebView.getSettings().setTextSize(TextSize.NORMAL);
break;
case 3:
mWebView.getSettings().setTextSize(TextSize.SMALLER);
break;
case 4:
mWebView.getSettings().setTextSize(TextSize.SMALLEST);
break;
public MyBitmapUtils() {
mMemoryCacheUtils = new MemoryCacheUtils();
mLocalCacheUtils = new LocalCacheUtils();
mNetCacheUtils = new NetCacheUtils(mLocalCacheUtils, mMemoryCacheUtils);
}