Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Nov 6, 2016
1 parent 3510ad7 commit 7a7cec5
Show file tree
Hide file tree
Showing 19 changed files with 688 additions and 97 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
|指示器加标题模式<br>水平显示|![效果示例](https://raw.githubusercontent.com/youth5201314/banner/master/image/5.png)

### 联系方式 <a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=KBkYGhAfGhEYEB5oWVkGS0dF" style="text-decoration:none;"><img src="http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_11.png"/></a>
![效果示例](https://raw.githubusercontent.com/youth5201314/banner/master/image/Android技术交流群二维码.png)
![效果示例](http://oceh51kku.bkt.clouddn.com/Android%E6%8A%80%E6%9C%AF%E4%BA%A4%E6%B5%81%E7%BE%A4%E4%BA%8C%E7%BB%B4%E7%A0%81.png)
* 如果遇到问题和建议欢迎在给我发送邮件或者加入qq群,希望让这个工程越来越完善。

## 常量
Expand Down Expand Up @@ -64,6 +64,7 @@
|startAutoPlay()|开始轮播|1.4开始,此方法只作用于banner加载完毕-->需要在start()后执行
|stopAutoPlay()|结束轮播|1.4开始,此方法只作用于banner加载完毕-->需要在start()后执行
|start()|开始进行banner渲染|1.4开始
|setOffscreenPageLimit(int limit)|同viewpager的方法作用一样|1.4.2开始
|setBannerTitle(String[] titles)| 设置轮播要显示的标题和图片对应(如果不传默认不显示标题)|1.3.3结束
|setBannerTitleList(List<String> titles)| 设置轮播要显示的标题和图片对应(如果不传默认不显示标题)|1.3.3结束
|setBannerTitles(List<String> titles)| 设置轮播要显示的标题和图片对应(如果不传默认不显示标题)|1.4开始
Expand Down Expand Up @@ -103,9 +104,9 @@
Gradle
```groovy
dependencies{
compile 'com.youth.banner:banner:1.4.1' //最新版本
compile 'com.youth.banner:banner:1.4.2' //最新版本
or
compile 'com.youth.banner:banner:1.3.3' //旧版本
compile 'com.youth.banner:banner:1.3.3' //旧版本,旧版本用法下面有跳转链接
}
```
或者引用本地lib
Expand Down Expand Up @@ -135,23 +136,33 @@ compile project(':banner')

#### Step 4.重写图片加载器
```java
public class GlideImageLoader implements ImageLoader {
public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
/**
常用的图片加载库:
Universal Image Loader:一个强大的图片加载库,包含各种各样的配置,最老牌,使用也最广泛。
Picasso: Square出品,必属精品。和OkHttp搭配起来更配呦!
Volley ImageLoader:Google官方出品,可惜不能加载本地图片~
Fresco:Facebook出的,天生骄傲!不是一般的强大。
Glide:Google推荐的图片加载库,专注于流畅的滚动。
*/

//Glide 加载图片简单用法
Glide.with(context).load(path).into(imageView);
or

//Picasso 加载图片简单用法
Picasso.with(context).load(path).into(imageView)
......

//用fresco加载图片简单用法
Uri uri = Uri.parse((String) path);
imageView.setImageURI(uri);
}
//提供createImageView 方法,如果不用可以不重写这个方法,方便fresco自定义ImageView
@Override
public ImageView createImageView(Context context) {
SimpleDraweeView simpleDraweeView=new SimpleDraweeView(context);
return simpleDraweeView;
}
}
```
Expand Down Expand Up @@ -264,6 +275,15 @@ protected void onCreate(Bundle savedInstanceState) {

## 更新说明

#### v1.4.2
banner优化更新<感谢 694551594,FeverCombo3,MIkeeJY >
* !!!注意!!ImageLoader已从接口改变成抽象类,请调整下代码哦!
* ImageLoader中增加ImageView控件创建方法createImageView(),可以满足fresco加载图片时扩展ImageView需求
* 修改关于banner刷新时需要第二轮才会更新图片问题(同title更新图片不更新问题),具体看demo
* 开放viewpager的setOffscreenPageLimit(int limit)方法
* 优化banner在开始0s~20s之间会出现的内存泄漏问题
* 优化最后一张到第一张之间滑动卡顿现象

#### v1.4.1
bug修改<感谢深圳-放飞,台北-Tom>
* 第一次加载一张图片(不能滑动[正常])-->刷新-->第二次加载多张图片(不能滑动[bug])
Expand Down
28 changes: 20 additions & 8 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -81,6 +73,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -90,6 +90,11 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/drawee/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/fbcore/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/fresco/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/imagepipeline-base/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.facebook.fresco/imagepipeline/0.12.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
Expand All @@ -105,14 +110,21 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="imagepipeline-0.12.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="imagepipeline-base-0.12.0" level="project" />
<orderEntry type="library" exported="" name="drawee-0.12.0" level="project" />
<orderEntry type="library" exported="" name="fresco-0.12.0" level="project" />
<orderEntry type="library" exported="" name="bolts-tasks-1.4.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" name="glide-3.7.0" level="project" />
<orderEntry type="library" exported="" name="fbcore-0.12.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
<orderEntry type="module" module-name="banner-banner" exported="" />
</component>
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:23+'
compile 'com.android.support:recyclerview-v7:23+'
compile "com.github.bumptech.glide:glide:3.7.0"
compile 'com.facebook.fresco:fresco:0.12.0'
compile project(':banner')
// compile 'com.youth.banner:banner:+'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -18,6 +19,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
16 changes: 16 additions & 0 deletions app/src/main/java/com/test/banner/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.test.banner;

import android.app.Application;
import android.content.Context;

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


public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);

}
}
29 changes: 29 additions & 0 deletions app/src/main/java/com/test/banner/CustomImageLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.test.banner;

import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.youth.banner.loader.ImageLoader;


public class CustomImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择
// Glide.with(context).load(path).into(imageView);

//用fresco加载图片
Uri uri = Uri.parse((String) path);
imageView.setImageURI(uri);

}
//提供createImageView 方法,方便fresco自定义ImageView
@Override
public ImageView createImageView(Context context) {
SimpleDraweeView simpleDraweeView=new SimpleDraweeView(context);
return simpleDraweeView;
}
}
16 changes: 0 additions & 16 deletions app/src/main/java/com/test/banner/GlideImageLoader.java

This file was deleted.

20 changes: 12 additions & 8 deletions app/src/main/java/com/test/banner/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.test.banner;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
Expand All @@ -14,6 +15,8 @@

import com.test.banner.common.BaseRecyclerAdapter;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerClickListener;

import java.util.Arrays;
Expand All @@ -29,7 +32,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case REFRESH_COMPLETE:
images = getResources().getStringArray(R.array.url2);
images = getResources().getStringArray(R.array.url4);
banner.setImages(Arrays.asList(images)).start();
mSwipeLayout.setRefreshing(false);
break;
Expand Down Expand Up @@ -68,22 +71,22 @@ protected void onCreate(Bundle savedInstanceState) {
*/

//简单使用
banner.setImages(Arrays.asList(images)).setImageLoader(new GlideImageLoader()).start();

/*//设置banner样式
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
banner.setImages(Arrays.asList(images)).setImageLoader(new CustomImageLoader()).start();
/*
//设置banner样式
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
//设置图片加载器
banner.setImageLoader(new GlideImageLoader());
banner.setImageLoader(new CustomImageLoader());
//设置图片集合
banner.setImages(Arrays.asList(images));
//设置banner动画效果
banner.setBannerAnimation(Transformer.DepthPage);
banner.setBannerAnimation(Transformer.CubeOut);
//设置标题集合(当banner样式有显示title时)
banner.setBannerTitles(Arrays.asList(titles));
//设置自动轮播,默认为true
banner.isAutoPlay(true);
//设置轮播时间
banner.setDelayTime(1500);
banner.setDelayTime(3000);
//设置指示器位置(当banner模式中有指示器时)
banner.setIndicatorGravity(BannerConfig.CENTER);
//banner设置方法全部调用完毕时最后调用
Expand All @@ -92,6 +95,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void OnBannerClick(int position) {
Toast.makeText(getApplicationContext(), "点击:" + position, Toast.LENGTH_SHORT).show();
Log.e("--",position+"");
}
});
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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:id="@+id/activity_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.test.banner.TestActivity">

</RelativeLayout>
6 changes: 5 additions & 1 deletion app/src/main/res/layout/header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
<com.youth.banner.Banner xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:image_scale_type="center_crop"
app:indicator_drawable_selected="@drawable/selected_radius"
app:title_background="#555CB85C"/>

10 changes: 7 additions & 3 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
<item>http://img.zcool.cn/community/01fd2756e142716ac72531cbf8bbbf.jpg</item>
<item>http://img.zcool.cn/community/0192a557a352ef0000012e7ed104e4.jpg</item>
</array>
<array name="url1">
<item>http://img.zcool.cn/community/01700557a7f42f0000018c1bd6eb23.jpg</item>
</array>
<array name="url2">
<item>http://img.zcool.cn/community/01d28457d621800000018c1bb7877e.jpg</item>
<item>http://img.zcool.cn/community/01ae5656e1427f6ac72531cb72bac5.jpg</item>
</array>
<array name="url4">
<item>http://img.zcool.cn/community/01b72057a7e0790000018c1bf4fce0.png</item>
<item>http://img.zcool.cn/community/01fca557a7f5f90000012e7e9feea8.jpg</item>
<item>http://img.zcool.cn/community/01996b57a7f6020000018c1bedef97.jpg</item>
<item>http://img.zcool.cn/community/01700557a7f42f0000018c1bd6eb23.jpg</item>
</array>
<array name="url3">
<item>http://img.zcool.cn/community/01700557a7f42f0000018c1bd6eb23.jpg</item>
</array>
<array name="title">
<item>51巅峰钜惠</item>
<item>十大星级品牌联盟,全场2折起</item>
Expand Down
16 changes: 8 additions & 8 deletions banner/banner-banner.iml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
Expand Down
Loading

0 comments on commit 7a7cec5

Please sign in to comment.