fresco加载图片


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    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.z.bwie.a01_fresco.MainActivity">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="fresco加载图片"
        android:onClick="jiazai"/>
    <com.facebook.drawee.view.SimpleDraweeView
        android:background="#000"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:id="@+id/drawee_view"
        app:placeholderImage="@drawable/icon_placeholder"
        app:placeholderImageScaleType="fitCenter"

        app:actualImageScaleType="focusCrop"

        app:progressBarImage="@drawable/icon_progress_bar"
        app:progressBarImageScaleType="centerInside"
        app:progressBarAutoRotateInterval="2000"

        app:failureImage="@drawable/icon_failure"
        app:failureImageScaleType="centerInside"

        app:retryImage="@drawable/icon_retry"
        app:retryImageScaleType="centerCrop"

        app:fadeDuration="3000"

        app:backgroundImage="@color/colorAccent"

        app:roundedCornerRadius="50dp"
        app:roundBottomLeft="true"
        app:roundTopLeft="true"
        app:roundBottomRight="true"
        app:roundTopRight="true"

        app:roundingBorderColor="#fff"
        app:roundingBorderWidth="10dp"
        />

</LinearLayout>
Fresco.initialize(this);

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

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

public class MainActivity extends AppCompatActivity {

    private String imageUrl = "https://m.360buyimg.com//n0//jfs//t6700//155//2098998076//156185//6cf95035//595dd5a5Nc3a7dab5.jpg";
    private SimpleDraweeView drawee_view;

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

        drawee_view = (SimpleDraweeView) findViewById(R.id.drawee_view);
    }
    public void jiazai(View view){
        Uri uri=Uri.parse(imageUrl);
        drawee_view.setImageURI(uri);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                //加载图片的地址
                .setUri(uri)
                //设置点击重试是否开启
                .setTapToRetryEnabled(true)
                //设置旧的Controller
                .setOldController(drawee_view.getController())
                //构建
                .build();
 //设置DraweeController
 drawee_view.setController(controller);

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值