fresco图片加载

例:



加依赖:

dependencies {
    compile 'com.facebook.fresco:fresco:1.5.0'
}

加权限:

<uses-permission android:name="android.permission.INTERNET"/>


主方法类:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Uri uri = Uri.parse("http://img.1985t.com/uploads/attaches/2017/12/141013-eSnS9sO.jpg");
        SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.img_head);
        draweeView.setImageURI(uri);

    }
}

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.day_0604_b.MainActivity">

    <com.facebook.drawee.view.SimpleDraweeView
        xmlns:fresco="http://schemas.android.com/tools"
        android:id="@+id/img_head"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        fresco:roundAsCircle="true" />

</RelativeLayout>

MyApplication类:
(<application/>在这个控件里加入属性:android:name=".MyApplication")

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //fresco的初始化
        Fresco.initialize(this);
    }
}























猜你喜欢

转载自blog.csdn.net/jun_tong/article/details/80587283