Fresco的基本使用
来源:互联网 发布:python goto语句 编辑:程序博客网 时间:2024/05/22 23:54
引入Fresco
编辑 build.gradle 文件:
compile 'com.facebook.fresco:fresco:0.12.0'// 在 API < 14 上的机器支持 WebP 时,需要添加compile 'com.facebook.fresco:animated-base-support:0.12.0'// 支持 GIF 动图,需要添加compile 'com.facebook.fresco:animated-gif:0.12.0'// 支持 WebP (静态图+动图),需要添加compile 'com.facebook.fresco:animated-webp:0.12.0'compile 'com.facebook.fresco:webpsupport:0.12.0'// 仅支持 WebP 静态图,需要添加compile 'com.facebook.fresco:webpsupport:0.12.0'
在加载图片之前,你必须初始化Fresco类。你只需要调用Fresco.initialize一次即可完成初始化,在 Application 里面初始化
package com.zhoujian.fresco;import android.app.Application;import com.facebook.drawee.backends.pipeline.Fresco;/** * Created by zhoujian on 2017/1/7. */public class AppApplication extends Application{ @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); }}
做完上面的工作后,你需要在 AndroidManifest.xml 中指定你的 Application 类。并设置网络权限
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zhoujian.fresco"> <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:name=".AppApplication" android:theme="@style/AppTheme"> <activity android:name=".activity.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application></manifest>
在xml布局文件中, 加入命名空间:
xmlns:fresco="http://schemas.android.com/apk/res-auto"
在布局中使用
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/fresco_imgeview" android:layout_marginTop="5dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_width="match_parent" android:layout_height="wrap_content" fresco:viewAspectRatio="1.33" fresco:placeholderImage="@mipmap/image_default" fresco:fadeDuration="300" fresco:actualImageScaleType="focusCrop" fresco:placeholderImageScaleType="fitCenter" fresco:failureImage="@mipmap/image_default" fresco:failureImageScaleType="centerInside" fresco:retryImage="@mipmap/image_default" fresco:retryImageScaleType="centerCrop" fresco:progressBarImage="@mipmap/image_default" fresco:progressBarImageScaleType="centerInside" fresco:progressBarAutoRotateInterval="1000" fresco:backgroundImage="@color/colorAccent" fresco:roundAsCircle="false" fresco:roundedCornerRadius="20dp" fresco:roundTopLeft="true" fresco:roundTopRight="true" fresco:roundBottomLeft="true" fresco:roundBottomRight="true" fresco:roundWithOverlayColor="#eeeeee" fresco:roundingBorderWidth="1dp" fresco:pressedStateOverlayImage="@android:color/transparent"/> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/fresco_imgeview1" android:layout_marginTop="5dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_width="match_parent" android:layout_height="wrap_content" fresco:viewAspectRatio="1.33" fresco:placeholderImage="@mipmap/image_default"/></LinearLayout>
在代码中加载
package com.zhoujian.fresco.activity;import android.app.Activity;import android.os.Bundle;import com.facebook.drawee.view.SimpleDraweeView;import com.zhoujian.fresco.R;import butterknife.BindView;import butterknife.ButterKnife;public class MainActivity extends Activity{ @BindView(R.id.fresco_imgeview) SimpleDraweeView mFrescoImgeview; @BindView(R.id.fresco_imgeview1) SimpleDraweeView mFrescoImgeview1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(MainActivity.this); setImage(); } private void setImage() { mFrescoImgeview.setImageURI("http://image.tianjimedia.com/uploadImages/2014/339/38/M7K1817T9KU1.jpg"); mFrescoImgeview1.setImageURI("http://img5.imgtn.bdimg.com/it/u=3432186896,3159823243&fm=21&gp=0.jpg"); }}
运行效果截图:
源码下载
源码下载:https://github.com/zeke123/FrescoDemo
0 0
- Fresco的基本使用
- Fresco的基本使用
- Fresco的基本使用
- Fresco图片库的基本使用
- Fresco 框架的基本使用
- Fresco(2)——fresco的基本使用
- 图片加载神器fresco----fresco的基本使用
- 图片框架:Fresco 的基本使用
- Fresco基本使用
- Fresco基本使用
- Fresco 基本使用
- Fresco基本使用基本介绍
- fresco的基本用法
- Fresco的基本使用和各种属性的含义,Fresco加载图片框架
- Fresco的使用
- Fresco的简单使用
- Fresco的使用
- Fresco的初步使用
- 基于Spring、Hibernate的通用DAO层与Service层的实现
- Uinty设置窗口大小和无边框模式
- 【Unity3D游戏开发】之常用代码 (二)
- 临时笔记&问题记录
- linux下查找某个字符串
- Fresco的基本使用
- 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题
- 献给初学labview数据采集的初学者
- myeclipse源码相关操作
- hibernate笔记
- angularjs radio、checkbox、ng-repeat
- 优化遍历查询语句(编程珠玑)
- 电磁波中的波段划分:L波段、S波段、C波段、X波段、Ku波段、K波段、Ka波段
- EXCEL2003每个单元格能放多少个字符?