android-google Volley framwork(2)
2016-01-11 12:06
357 查看
> how to use the common request types that Volley supports:
Up a Request Queue for an example.
Here is a sample implementation for an in-memory
and implements the
Here is an example of how to instantiate an
使用Gson解析Json数据。
StringRequest. Specify a URL and receive a raw string in response. See Setting
Up a Request Queue for an example.
ImageRequest. Specify a URL and receive an image in response.
JsonObjectRequestand
JsonArrayRequest(both subclasses of
JsonRequest). Specify a URL and get a JSON object or array (respectively) in response.
Here is a sample implementation for an in-memory
LruBitmapCacheclass. It extends the
LruCacheclass
and implements the
ImageLoader.ImageCacheinterface:
import android.graphics.Bitmap; import android.support.v4.util.LruCache; import android.util.DisplayMetrics; import com.android.volley.toolbox.ImageLoader.ImageCache; public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache { public LruBitmapCache(int maxSize) { super(maxSize); } public LruBitmapCache(Context ctx) { this(getCacheSize(ctx)); } @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } @Override public Bitmap getBitmap(String url) { return get(url); } @Override public void putBitmap(String url, Bitmap bitmap) { put(url, bitmap); } // Returns a cache size equal to approximately three screens worth of images. public static int getCacheSize(Context ctx) { final DisplayMetrics displayMetrics = ctx.getResources(). getDisplayMetrics(); final int screenWidth = displayMetrics.widthPixels; final int screenHeight = displayMetrics.heightPixels; // 4 bytes per pixel final int screenBytes = screenWidth * screenHeight * 4; return screenBytes * 3; } }
Here is an example of how to instantiate an
ImageLoaderto use this cache:
RequestQueue mRequestQueue; // assume this exists. ImageLoader mImageLoader = new ImageLoader(mRequestQueue, new LruBitmapCache( LruBitmapCache.getCacheSize()));
使用Gson解析Json数据。
相关文章推荐
- Android实用工具之三—图片处理工具
- Android 四种启动模式
- Android仿QQ滑动弹出菜单标记已读、未读消息
- Android复选框对话框用法实例简析
- 专为Android加载图片——Fresco
- Android实用工具之二—APK工具
- Android编程之四种Activity加载模式分析
- android颜色
- MAC下Android Studio快捷键的配置
- android 集成百度地图
- android pm/am命令
- android 给textview部分文字设置点击事件
- Android实用工具之一—时间戳工具
- android消息处理机制学习(四)-AsyncTask的原理分析
- android xml bitmap 实现波浪线效果
- android Service总结
- Android的数据库ORM框架:Sugar ORM
- Android开发-动态布局小记
- Android应用程序模型之应用程序,任务,进程,线程分析
- Android平台驱动编写实例