facebook图片加载框架Fresco入门教程

在gradle中导入fresco库(切记关掉本地缓存,不然下载不了setting->gradle->offline work不要勾选

compile 'com.facebook.fresco:fresco:0.8.0+'

在manifest中加入权限

设置application

public class MainApplication extends Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }

布局文件和activity文件:

public class MainActivity extends Activity { private SimpleDraweeView view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activitymain); view = (SimpleDraweeView) findViewById(R.id.imageview); view.setImageURI(Uri.parse("http://7u2n7b.com1.z0.glb.clouddn.com/242b2de08019d85b6efd1420ea36f5c0.jpg")); } }

fresco加载本地图片方法

// 注意只有一个/ image.setImageURI(Uri.parse("asset:/asset图片路径"));

fresco对URI的支持
File on network http://, https:// HttpURLConnection or network layer
File on device file:// FileInputStream
Content provider content:// ContentResolver
Asset in app asset:/ AssetManager
Resource in app res:// Resources.openRawResource