Fresco加载一张图片

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/L59_1/article/details/79958552

//访问网络的权限

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

//fresco图片加载依赖
compile ‘com.facebook.fresco:fresco:0.12.0’

布局

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="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.bwei.fresco_photo.MainActivity">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/myImage"
        android:layout_width="300dp"
        android:layout_height="200dp" />
</LinearLayout>

MainActivity

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {

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

        Uri uri = Uri.parse("http://4493bz.1985t.com/uploads/allimg/160823/5-160R3093921.jpg");
        SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.myImage);
        draweeView.setImageURI(uri);
    }
}

MyApplication

import android.app.Application;

import com.facebook.drawee.backends.pipeline.Fresco;

/**
 * Created by ass on 2018/04/10.
 */

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页