Skip to content

Commit 4b6cbc0

Browse files
committed
readme和demo
1 parent 0d31b48 commit 4b6cbc0

File tree

8 files changed

+204
-7
lines changed

8 files changed

+204
-7
lines changed

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,186 @@
11
# FrescoImageView
2+
3+
FrescoImageView是一种Android平台的图像控件,可以异步加载网络图片、项目资源和本地图片,并且支持双指缩放、图片的基本处理以及Fresco的所有特性。
4+
5+
该控件基于Facebook的图像加载库Fresco封装,Fresco的所有方法和属性都可以使用。
6+
7+
## 特性
8+
* 直接继承Fresco的DraweeView,本质是View,同时兼容Fresco的所有参数和方法
9+
* 加载图片只需一步,无需繁杂的设置
10+
* 支持双指缩放,并且支持点击事件
11+
12+
Project site: <https://github.com/HomHomLin/FrescoImageView>.
13+
14+
最新版本:v1.1.0
15+
16+
##导入项目
17+
18+
**Gradle dependency:**
19+
``` groovy
20+
compile 'homhomlin.lib:frescoimageview:1.1.0'
21+
```
22+
23+
or
24+
25+
**Maven dependency:**
26+
``` xml
27+
<dependency>
28+
<groupId>homhomlin.lib</groupId>
29+
<artifactId>frescoimageview</artifactId>
30+
<version>1.1.0</version>
31+
</dependency>
32+
```
33+
34+
35+
##用法
36+
37+
###导入Fresco
38+
39+
在项目导入FrescoImageView后,还需要导入Fresco,如下:
40+
41+
``` groovy
42+
compile 'com.facebook.fresco:fresco:0.9.0'
43+
```
44+
45+
截止至当前Readme编写时间,Fresco的最新版本为0.9.0。
46+
47+
FrescoImageView本身并不包含Fresco。
48+
49+
###配置Fresco
50+
51+
在项目的AndroidManifest.xml中添加网络访问权限(视需求而定)。
52+
53+
```xml
54+
<uses-permission android:name="android.permission.INTERNET"/>
55+
```
56+
57+
在项目的Application类中配置Fresco,这里其实是Fresco的内容。
58+
59+
``` java
60+
public class App extends Application{
61+
@Override
62+
public void onCreate() {
63+
super.onCreate();
64+
Fresco.initialize(this);
65+
}
66+
}
67+
```
68+
69+
###添加控件到XML
70+
71+
在需要添加的界面xml中添加组件。
72+
73+
FrescoImageView提供两种组件,分别是FrescoImageView(普通控件)和FrescoZoomImageView(可缩放控件),根据需要添加控件,以下以FrescoZoomImageView为例:
74+
75+
``` xml
76+
<lib.lhh.fiv.library.FrescoZoomImageView
77+
android:id="@+id/fiv"
78+
fresco:actualImageScaleType="fitCenter"
79+
android:layout_width="match_parent"
80+
android:layout_height="match_parent"/>
81+
```
82+
83+
在代码中find该组件。
84+
85+
```java
86+
FrescoZoomImageView frescoImageView = (FrescoZoomImageView)findViewById(R.id.fiv);
87+
```
88+
89+
###加载网络图片
90+
91+
调用void loadView(String url, int defaultResID)方法。
92+
93+
url表示需要加载的网络图片地址,defaultResID表示占位图(默认图)。
94+
95+
```java
96+
frescoImageView.loadView(mImgUrl,R.mipmap.ic_launcher);
97+
```
98+
99+
如果需要先显示默认图,然后加载显示一张低分辨率的图,最后再显示原图,可以使用void loadView(String lowUrl ,String url, int defaultResID)方法,lowUrl表示低分辨率图片地址。
100+
101+
###加载本地图片
102+
103+
调用void loadLocalImage(String path, int defaultRes)方法。
104+
105+
path表示本地图片的绝对路径。
106+
107+
```java
108+
frescoImageView.loadLocalImage(path,R.mipmap.ic_launcher);
109+
```
110+
111+
###加载项目资源
112+
113+
选择以上任意一个方法,非defaultResId参数填写为null即可。
114+
115+
```java
116+
frescoImageView.loadLocalImage(null,R.mipmap.ic_launcher);
117+
```
118+
119+
###点击监听
120+
121+
如果你使用的是FrescoZoomImageView,则需要调用setOnDraweeClickListener(OnClickListener l)方法来设置点击事件的监听。
122+
123+
如果你使用的是FrescoImageView,则可以直接使用setOnClicklistener(OnClickListener l)。
124+
125+
###开启和关闭gif动画
126+
127+
如果你的图片是gif类型的,则我们可以控制FrescoImageView的Gif动画,通过FrescoImageView的setAnim(boolean anim)来控制,默认情况下,我们是开启动画的。
128+
129+
###设置圆形
130+
131+
如果你需要将显示的图片变为圆形,则可以通过asCircle()方法。
132+
133+
```java
134+
frescoImageView.asCircle();
135+
```
136+
137+
###Gif图片设置为圆形
138+
139+
由于Fresco的原因,如果你需要将gif设置为圆形,则需要使用setCircle(int overlay_color)方法,overlay_color为背景图颜色。
140+
141+
```java
142+
frescoImageView.setCircle(Color.WHITE);
143+
```
144+
145+
###设置圆角
146+
147+
通过setCornerRadius(float radius)方法,并传入需要的角度即可实现圆角和边角的切割。
148+
149+
```java
150+
frescoImageView.setCornerRadius(10);
151+
```
152+
153+
###设置图像处理器
154+
155+
你可能需要对图片做额外的处理,那么你可以编写一个Fresco的PostProcessor,并通过setPostProcessor(PostProcessor)方法来设置一个处理器。
156+
157+
```java
158+
frescoImageView.setPostProcessor(postProcessor);
159+
```
160+
161+
###其他
162+
163+
FrescoImageView基于Fresco封装,因此Fresco的用法同样适用于FrescoImageView。
164+
165+
同样,FrescoZoomImageView也支持以上说的api和Fresco的方法。
166+
167+
具体请看Fresco:[Fresco的Github](https://github.com/facebook/fresco)
168+
169+
## Developed By
170+
171+
* Linhonghong - <linhh90@163.com>
172+
173+
##License
174+
Copyright 2016 LinHongHong
175+
176+
Licensed under the Apache License, Version 2.0 (the "License");
177+
you may not use this file except in compliance with the License.
178+
You may obtain a copy of the License at
179+
180+
http://www.apache.org/licenses/LICENSE-2.0
181+
182+
Unless required by applicable law or agreed to in writing, software
183+
distributed under the License is distributed on an "AS IS" BASIS,
184+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185+
See the License for the specific language governing permissions and
186+
limitations under the License.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
testCompile 'junit:junit:4.12'
2525
compile 'com.android.support:appcompat-v7:23.1.1'
26-
// compile 'homhomlin.lib:frescoimageview:1.0.0'
26+
// compile 'homhomlin.lib:frescoimageview:1.1.0'
2727
// compile 'com.facebook.fresco:fresco:0.9.0'
2828
compile project(':lib.lhh.fiv.library')
2929
compile 'com.facebook.fresco:imagepipeline-okhttp:0.9.0'

app/src/main/java/com/lhh/frescoimageview/demo/FrescoImageViewActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ protected void onCreate(Bundle savedInstanceState) {
1717
super.onCreate(savedInstanceState);
1818
setContentView(R.layout.activity_fresco_imgeview);
1919
FrescoImageView frescoImageView = (FrescoImageView)findViewById(R.id.fiv);
20+
frescoImageView.asCircle();
2021
frescoImageView.loadView(mImgUrl,R.mipmap.ic_launcher);
2122
}
2223
}

app/src/main/res/layout/activity_fresco_imgeview.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
android:orientation="vertical"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:background="#000000">
7+
android:gravity="center"
8+
android:background="#ffffff">
89
<lib.lhh.fiv.library.FrescoImageView
910
android:id="@+id/fiv"
1011
fresco:actualImageScaleType="fitCenter"
11-
android:layout_width="match_parent"
12-
android:layout_height="match_parent"/>
12+
android:layout_width="250dp"
13+
android:layout_height="250dp"/>
1314
</LinearLayout>

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919
PROJ_GROUP=homhomlin.lib
20-
PROJ_VERSION=1.0.0
20+
PROJ_VERSION=1.1.0
2121
PROJ_NAME=FrescoImageView
2222
PROJ_WEBSITEURL=https://github.com/HomHomLin/FrescoImageView
2323
PROJ_ISSUETRACKERURL=
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="lib.lhh.fiv.library"
3-
android:versionCode="1000"
4-
android:versionName="1.0.0" >
3+
android:versionCode="1100"
4+
android:versionName="1.1.0" >
55
<application>
66
</application>
77
</manifest>

lib.lhh.fiv.library/src/lib.lhh.fiv/library/FrescoImageView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,10 @@ public void setAnim(boolean b){
217217
public boolean isAnim(){
218218
return mAnim;
219219
}
220+
221+
public void asCircle(){
222+
RoundingParams roundingParams = RoundingParams.asCircle();
223+
this.getHierarchy().setRoundingParams(roundingParams);
224+
}
220225
}
221226

lib.lhh.fiv.library/src/lib.lhh.fiv/library/FrescoZoomImageView.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,10 @@ public void setAnim(boolean b){
225225
public boolean isAnim(){
226226
return mAnim;
227227
}
228+
229+
public void asCircle(){
230+
RoundingParams roundingParams = RoundingParams.asCircle();
231+
this.getHierarchy().setRoundingParams(roundingParams);
232+
}
228233
}
229234

0 commit comments

Comments
 (0)