【Android】 分享一个完整的项目,适合新手!
写这个app之前是因为看了头条的一篇文章:http://www.managershare.com/post/155110,然后心想要不做一个这样的app,让手机计算就行了。也就没多想就去开始整了。
/** * 初始化imageLoader */ public void initImageLoader() { File cacheDir = StorageUtils.getCacheDirectory(getApplicationContext()); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( getApplicationContext()) .memoryCache(new LruMemoryCache(5 * 1024 * 1024)) .memoryCacheSize(10 * 1024 * 1024) .discCache(new UnlimitedDiscCache(cacheDir)) .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) .build(); ImageLoader.getInstance().init(config); } public DisplayImageOptions getOptions(int drawableId) { return new DisplayImageOptions.Builder().showImageOnLoading(drawableId) .showImageForEmptyUri(drawableId).showImageOnFail(drawableId) .resetViewBeforeLoading(true).cacheInMemory(true) .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY) .bitmapConfig(Bitmap.Config.RGB_565).build(); }
2.使用时调用:
ImageLoader.getInstance().displayImage( avatarUrl, holder.mImage, MyApplication.getInstance().getOptions( R.drawable.user_icon_default_main), new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { super.onLoadingComplete(imageUri, view, loadedImage); } });
// 设置PullToRefresh mListView.setMode(Mode.BOTH); mListView.setOnRefreshListener(new OnRefreshListener2<ListView>() { // 下拉Pulling Down @Override public void onPullDownToRefresh( PullToRefreshBase<ListView> refreshView) { String label = DateUtils.formatDateTime(MainAct.this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); mListView.setMode(Mode.BOTH); pullFromUser = true; mRefreshType = RefreshType.REFRESH; pageNum = 0; lastItemTime = getCurrentTime(); //获取数据 fetchData(); } // 上拉Pulling Up @Override public void onPullUpToRefresh( PullToRefreshBase<ListView> refreshView) { // 上拉的时候添加选项 mRefreshType = RefreshType.LOAD_MORE; //获取数据 fetchData(); } }); actualListView = mListView.getRefreshableView(); actualListView.setFastScrollEnabled(true); mEntities = new ArrayList<RankEntity>(); mAdapter = new MainListAdapter(MainAct.this, mEntities); actualListView.setAdapter(mAdapter); if (mEntities.size() == 0) { fetchData(); } mListView.setState(State.RELEASE_TO_REFRESH, true);