fresco加载图片

  需要的依赖

compile 'com.facebook.fresco:fresco:0.11.0'
清单文件注册
android:name=".MyApplication"
添加网络权限
  activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <Button
                android:id="@+id/bt_fresco_spimg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="带进度条的图片" />

            <Button
                android:id="@+id/bt_fresco_crop"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="图片的不同裁剪" />

            <Button
                android:id="@+id/bt_fresco_circleAndCorner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="圆形和圆角图片" />

            <Button
                android:id="@+id/bt_fresco_jpeg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="渐进式展示图片" />

            <Button
                android:id="@+id/bt_fresco_gif"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="GIF动画图片" />

            <Button
                android:id="@+id/bt_fresco_multi"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="多图请求及图片复用" />

            <Button
                android:id="@+id/bt_fresco_listener"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="图片加载监听" />

            <Button
                android:id="@+id/bt_fresco_resize"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="图片缩放和旋转" />

            <Button
                android:id="@+id/bt_fresco_modifyImg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="修改图片" />

            <Button
                android:id="@+id/bt_fresco_autoSizeImg"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="动态展示图片" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

                MainActivity.java

package com.example.bawei.myxiangmu2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.example.bawei.myxiangmu2.activity.FrescoAutoSizeActivity;
import com.example.bawei.myxiangmu2.activity.FrescoCircleAndCornerActivity;
import com.example.bawei.myxiangmu2.activity.FrescoCropActivity;
import com.example.bawei.myxiangmu2.activity.FrescoGifAcitivity;
import com.example.bawei.myxiangmu2.activity.FrescoJpegActivity;
import com.example.bawei.myxiangmu2.activity.FrescoListenerActivity;
import com.example.bawei.myxiangmu2.activity.FrescoModifyActivity;
import com.example.bawei.myxiangmu2.activity.FrescoMultiActivity;
import com.example.bawei.myxiangmu2.activity.FrescoResizeActivity;
import com.example.bawei.myxiangmu2.activity.FrescoSpimgActivity;


/**
 *  1.写布局
 *  2.搭建Fresco环境.在项目的build.grade文件里添加依赖,在application中初始化Fresco,配置网络权限
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button bt_fresco_spimg;
    private Button bt_fresco_crop;
    private Button bt_fresco_circleAndCorner;
    private Button bt_fresco_jpeg;
    private Button bt_fresco_gif;
    private Button bt_fresco_multi;
    private Button bt_fresco_listener;
    private Button bt_fresco_resize;
    private Button bt_fresco_modifyImg;
    private Button bt_fresco_autoSizeImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化控件
        initView();

    }

    //设置点击事件
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            // 带进度条的图片
            case R.id.bt_fresco_spimg:
                Intent spimgIntent = new Intent(this, FrescoSpimgActivity.class);
                startActivity(spimgIntent);
                break;

            //对图片进行不同的裁剪
            case R.id.bt_fresco_crop:
                Intent cropIntent = new Intent(this, FrescoCropActivity.class);
                startActivity(cropIntent);
                break;

            //圆形和圆角图片
            case R.id.bt_fresco_circleAndCorner:
                Intent circleAndCorner = new Intent(this, FrescoCircleAndCornerActivity.class);
                startActivity(circleAndCorner);
                break;

            // 渐进式展示图片
            case R.id.bt_fresco_jpeg:
                Intent JpegIntent = new Intent(this, FrescoJpegActivity.class);
                startActivity(JpegIntent);
                break;

            //GIF动画图片
            case R.id.bt_fresco_gif:
                Intent GifIntent = new Intent(this, FrescoGifAcitivity.class);
                startActivity(GifIntent);
                break;

            //多图请求及图片复用
            case R.id.bt_fresco_multi:
                Intent MultiIntent = new Intent(this, FrescoMultiActivity.class);
                startActivity(MultiIntent);
                break;

            //图片加载监听
            case R.id.bt_fresco_listener:
                Intent ListenerIntent = new Intent(this, FrescoListenerActivity.class);
                startActivity(ListenerIntent);
                break;

            //图片修改和旋转
            case R.id.bt_fresco_resize:
                Intent ResizeIntent = new Intent(this,FrescoResizeActivity.class);
                startActivity(ResizeIntent);
                break;

            //修改图片
            case R.id.bt_fresco_modifyImg:
                Intent ModifyIntent = new Intent(this, FrescoModifyActivity.class);
                startActivity(ModifyIntent);
                break;

            //动态展示图片
            case R.id.bt_fresco_autoSizeImg:
                Intent AutoSizeIntent = new Intent(this, FrescoAutoSizeActivity.class);
                startActivity(AutoSizeIntent);
                break;
        }
    }

    //初始化控件
    private void initView() {
        bt_fresco_spimg = (Button) findViewById(R.id.bt_fresco_spimg);
        bt_fresco_crop = (Button) findViewById(R.id.bt_fresco_crop);
        bt_fresco_circleAndCorner = (Button) findViewById(R.id.bt_fresco_circleAndCorner);
        bt_fresco_jpeg = (Button) findViewById(R.id.bt_fresco_jpeg);
        bt_fresco_gif = (Button) findViewById(R.id.bt_fresco_gif);
        bt_fresco_multi = (Button) findViewById(R.id.bt_fresco_multi);
        bt_fresco_listener = (Button) findViewById(R.id.bt_fresco_listener);
        bt_fresco_resize = (Button) findViewById(R.id.bt_fresco_resize);
        bt_fresco_modifyImg = (Button) findViewById(R.id.bt_fresco_modifyImg);
        bt_fresco_autoSizeImg = (Button) findViewById(R.id.bt_fresco_autoSizeImg);

        bt_fresco_spimg.setOnClickListener(this);
        bt_fresco_crop.setOnClickListener(this);
        bt_fresco_circleAndCorner.setOnClickListener(this);
        bt_fresco_jpeg.setOnClickListener(this);
        bt_fresco_gif.setOnClickListener(this);
        bt_fresco_multi.setOnClickListener(this);
        bt_fresco_listener.setOnClickListener(this);
        bt_fresco_resize.setOnClickListener(this);
        bt_fresco_modifyImg.setOnClickListener(this);
        bt_fresco_autoSizeImg.setOnClickListener(this);
    }

}
        
                     MyApplication.java
package com.example.bawei.myxiangmu2;

import android.app.Application;

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

/**
 * Created by bawei on 2017/12/25.
 */

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值