Fresco静态图片获取

    fresco图片框架依赖:

    compile 'com.facebook.fresco:fresco:0.14.1'

<!-- 访问网络的权限 -->
<uses-permission android:name="android.permission.INTERNET"/>

    <-- 布局文件-->

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

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/main_sdv"
        android:layout_width="300px"
        android:layout_height="300px"
        android:layout_centerInParent="true"
        ></com.facebook.drawee.view.SimpleDraweeView>

</RelativeLayout>

    <!--  创建App类继承Application -->

    

package com.example.dell.a1511r0410;

import android.app.Application;
import com.facebook.drawee.backends.pipeline.Fresco;

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        //初始化Fresco使用默认配置
        Fresco.initialize(this);
    }
}

    <!--  Activity中的实现 -->

package com.example.dell.a1511r0410;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {

    private SimpleDraweeView main_sdv;
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        //找到资源控件的ID
        main_sdv = findViewById(R.id.main_sdv);

        //创建将要下载的图片的URI
        Uri imageUri = Uri.parse("http://p2.wmpic.me/article/2014/09/03/1409716540_nBTYEUBy.jpg");

        //开始下载
         main_sdv.setImageURI(imageUri);
    }
}


阅读更多
想对作者说点什么? 我来说一句

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