Skip to content

Commit

Permalink
更新详情看文档最下方
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Sep 6, 2017
1 parent d11f1d0 commit 67661ea
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 62 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
### 联系方式 <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>
![效果示例](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群,希望让这个工程越来越完善。
* 群满可以加群2:594813900

## 常量
|常量名称|描述|所属方法
Expand All @@ -43,6 +44,8 @@
|BannerConfig.RIGHT| 指示器居右|setIndicatorGravity

## 动画常量类(setBannerAnimation方法调用)
[ViewPagerTransforms](https://github.com/ToxicBakery/ViewPagerTransforms) `动画时集成的第三方库,可能有兼容问题导致position位置不准确,你可以选择参考动画然后自定义动画`

|常量类名|
|---|
|Transformer.Default|
Expand Down Expand Up @@ -107,6 +110,8 @@
|indicator_drawable_selected| reference|指示器选中效果
|indicator_drawable_unselected| reference|指示器未选中效果
|image_scale_type| enum |和imageview的ScaleType作用一样
|banner_default_image| reference | 当banner数据为空是显示的默认图片
|banner_layout| reference |自定义banner布局文件,但是必须保证id的名称一样(你可以将banner的布局文件复制出来进行修改)


### <a href="http://youth5201314.github.io/2016/08/24/ViewPager%E5%88%87%E6%8D%A2%E5%8A%A8%E7%94%BBPageTransformer%E4%BD%BF%E7%94%A8/" target="_blank"> [ 点击查看 ViewPager的PageTransformer用法 ]
Expand All @@ -118,7 +123,7 @@
Gradle
```groovy
dependencies{
compile 'com.youth.banner:banner:1.4.9' //最新版本
compile 'com.youth.banner:banner:1.4.10' //最新版本
}
```
或者引用本地lib
Expand Down Expand Up @@ -277,7 +282,7 @@ protected void onStop() {

* 问:怎么显示的一片空白?
* 答:<br>
1、没有添加网络权限就抱怨有问题,然后就拒绝使用,我能说什么?<br>
1、没有添加网络权限<br>
2、检查图片链接是否能打开。
* 问:怎么加载其他图片资源(资源文件、文件、Uri、assets、raw、ContentProvider、sd卡资源)?
* 答:列如!如果你使用的是glide,那么可以如下操作,其他图片图片加载框架可能有不同
Expand Down Expand Up @@ -306,13 +311,28 @@ protected void onStop() {

* 答:首先我先要说很多软件的指示器也是矩形的,然后banner的指示器可以设置color、资源图片、drawable文件夹自定义xml,
所以形状你自己可以根据需求定义哦!


* 问:为什么banner的点击事件没有反应,需要下一次轮播才行?

* 答:请将点击事件放在start方法之前执行,详情可以看demo。

## Thanks

- [ViewPagerTransforms](https://github.com/ToxicBakery/ViewPagerTransforms)

## 更新说明

#### v1.4.10
很久没有维护banner了,有工作原因比较忙,也有经常遇见一些素质低的人,感觉整个世界都欠他们的,特别影响心情。就放弃更新维护了,
但是这半年每天邮箱都会收到各种建议反馈,也有很多人私信我,所以在此修复一些当前版本bug,关于有朋友要求让轮播类型可以自定义,不局限于imageview的需求,
这个过段时间再发布一个全新的banner版本,会更加灵活,就不在原来的上面弄了,到时候分两个版本走!

* 解决轮播手动滑动跳转问题:从第一张-->最后一张-->直接跳转到第二张
* 解决update刷新轮播图崩溃问题
* 将onPageScrolled和onPageSelected方法返回的position转成真实的position
* 增加属性banner_default_image,设置当banner数据为空是显示的默认图片
* 增加属性banner_layout,可以自定义布局文件,但是必须保证id的名称一样

#### v1.4.9
banner 优化更新
* 废弃以前的点击事件(当然还是可以使用以前的方法),增加新的setOnBannerListener点击事件,下标从0开始
Expand Down
27 changes: 8 additions & 19 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.2.0/jars" />
<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-compat/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-utils/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-fragment/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/24.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/24.2.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/exploded-aar/com.zxy.android/recovery/0.0.8/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 @@ -107,7 +91,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-media-compat-24.2.0" level="project" />
<orderEntry type="library" exported="" name="imagepipeline-0.12.0" level="project" />
Expand All @@ -132,7 +116,12 @@
<orderEntry type="library" exported="" name="glide-3.7.0" level="project" />
<orderEntry type="library" exported="" name="fbcore-0.12.0" level="project" />
<orderEntry type="module" module-name="banner-banner" exported="" />
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-v4-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-compat-26.0.0-alpha1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-26.0.0-alpha1" level="project" />
</component>
</module>
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
applicationId "com.test.banner"
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/test/banner/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
listView.setOnItemClickListener(this);

//简单使用
banner.setImages(App.images)
banner.setImages(new ArrayList<>())
.setImageLoader(new GlideImageLoader())
.setOnBannerListener(this)
.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void initData(){
transformers.add(AccordionTransformer.class);
transformers.add(BackgroundToForegroundTransformer.class);
transformers.add(ForegroundToBackgroundTransformer.class);
transformers.add(CubeInTransformer.class);
transformers.add(CubeInTransformer.class);//兼容问题,慎用
transformers.add(CubeOutTransformer.class);
transformers.add(DepthPageTransformer.class);
transformers.add(FlipHorizontalTransformer.class);
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/com/test/banner/loader/GlideImageLoader.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.test.banner.loader;

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

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.test.banner.App;
import com.test.banner.ui.GlideRoundTransform;
import com.test.banner.ui.RoundAngleImageView;
import com.youth.banner.loader.ImageLoader;


Expand All @@ -17,9 +15,12 @@ public void displayImage(Context context, Object path, ImageView imageView) {
//具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择
Glide.with(context.getApplicationContext())
.load(path)
.crossFade()
.into(imageView);
}


// @Override
// public ImageView createImageView(Context context) {
// //圆角
// return new RoundAngleImageView(context);
// }
}
52 changes: 52 additions & 0 deletions app/src/main/java/com/test/banner/ui/GlideRoundTransform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.test.banner.ui;


import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

public class GlideRoundTransform extends BitmapTransformation {

private static float radius = 0f;

public GlideRoundTransform(Context context) {
this(context, 4);
}

public GlideRoundTransform(Context context, int dp) {
super(context);
this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
}

@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return roundCrop(pool, toTransform);
}

private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;

Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
}

Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
canvas.drawRoundRect(rectF, radius, radius, paint);
return result;
}

@Override public String getId() {
return getClass().getName() + Math.round(radius);
}
}
124 changes: 124 additions & 0 deletions app/src/main/java/com/test/banner/ui/RoundAngleImageView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.test.banner.ui;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;


public class RoundAngleImageView extends ImageView {

private Paint paint;
private int roundWidth = 5;
private int roundHeight = 5;
private Paint paint2;

public RoundAngleImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}

public RoundAngleImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}

public RoundAngleImageView(Context context) {
super(context);
init(context, null);
}

private void init(Context context, AttributeSet attrs) {
paint = new Paint();
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
paint2 = new Paint();
paint2.setXfermode(null);
}

@Override
public void draw(Canvas canvas) {
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas2 = new Canvas(bitmap);
super.draw(canvas2);
drawLiftUp(canvas2);
drawRightUp(canvas2);
drawLiftDown(canvas2);
drawRightDown(canvas2);
canvas.drawBitmap(bitmap, 0, 0, paint2);
bitmap.recycle();
}

private void drawLiftUp(Canvas canvas) {
Path path = new Path();
path.moveTo(0, roundHeight);
path.lineTo(0, 0);
path.lineTo(roundWidth, 0);
path.arcTo(new RectF(
0,
0,
roundWidth*2,
roundHeight*2),
-90,
-90);
path.close();
canvas.drawPath(path, paint);
}

private void drawLiftDown(Canvas canvas) {
Path path = new Path();
path.moveTo(0, getHeight()-roundHeight);
path.lineTo(0, getHeight());
path.lineTo(roundWidth, getHeight());
path.arcTo(new RectF(
0,
getHeight()-roundHeight*2,
0+roundWidth*2,
getHeight()),
90,
90);
path.close();
canvas.drawPath(path, paint);
}

private void drawRightDown(Canvas canvas) {
Path path = new Path();
path.moveTo(getWidth()-roundWidth, getHeight());
path.lineTo(getWidth(), getHeight());
path.lineTo(getWidth(), getHeight()-roundHeight);
path.arcTo(new RectF(
getWidth()-roundWidth*2,
getHeight()-roundHeight*2,
getWidth(),
getHeight()), 0, 90);
path.close();
canvas.drawPath(path, paint);
}

private void drawRightUp(Canvas canvas) {
Path path = new Path();
path.moveTo(getWidth(), roundHeight);
path.lineTo(getWidth(), 0);
path.lineTo(getWidth()-roundWidth, 0);
path.arcTo(new RectF(
getWidth()-roundWidth*2,
0,
getWidth(),
0+roundHeight*2),
-90,
90);
path.close();
canvas.drawPath(path, paint);
}

}
9 changes: 8 additions & 1 deletion app/src/main/res/layout/activity_custom_view_pager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
android:layout_height="match_parent">
<com.youth.banner.Banner
android:id="@+id/banner"
app:layout_id="@layout/banner_custom_viewpager"
app:banner_layout="@layout/banner_custom_viewpager"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="@color/colorPrimary"
android:layout_below="@id/banner"
android:text="这是一个修改banner布局文件的例子,你可以按照这个套路修改里面的内容,比如修改指示器位置啊,文字的大小啊,他们之间的间距啊,或者修改他们的摆放位置等待"/>
</RelativeLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/banner_custom_viewpager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@
</FrameLayout>
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/bannerDefaultImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:visibility="gone"/>
</RelativeLayout>
Loading

0 comments on commit 67661ea

Please sign in to comment.