Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Sep 2, 2016
1 parent 44c7531 commit eb49d45
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 144 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Android图片轮播控件 *如果对你有帮助请star哦!*
[![Apache 2.0 License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0.html)

<br>
现在的绝大数app都有banner界面,实现循环播放多个广告图片和手动滑动循环等功能。因为ViewPager并不支持循环翻页,
所以要实现循环还得需要自己去动手,我就把项目中的控件剔了出来,希望大家觉得有用。目前框架可以进行不同样式、不同动画设置,
Expand Down Expand Up @@ -78,7 +79,6 @@ compile project(':banner')
|setOnBannerClickListener(this)|设置点击事件,下标是从1开始
|setOnBannerImageListener(this)|设置图片加载事件,可以自定义图片加载方式
|setOnPageChangeListener(this)|设置viewpager的滑动监听
|setScrollerTime(int duration)|设置viewpager的切换速度,(单位毫秒,默认800)
|setBannerAnimation(Class<? extends PageTransformer> transformer)|设置viewpager的默认动画,传值见动画表
|setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer)|设置viewpager的自定义动画

Expand Down
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="module" module-name="banner-banner" exported="" />
</component>
</module>
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</intent-filter>
</activity>
<activity android:name=".BannerActivity" />
<activity android:name=".Banner2Activity"/>
<activity android:name=".Banner3Activity"/>
<activity android:name=".BannerSeniorActivity"/>
<activity android:name=".BannerCustomActivity"/>
</application>

</manifest>
7 changes: 4 additions & 3 deletions app/src/main/java/com/test/banner/BannerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerClickListener;

public class BannerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner);
getSupportActionBar().setTitle(getIntent().getStringExtra("des"));
String[] images= getResources().getStringArray(R.array.url);
String[] images= getResources().getStringArray(R.array.url2);
String[] titles= getResources().getStringArray(R.array.title);
int position=getIntent().getIntExtra("position",0);
Banner banner = (Banner) findViewById(R.id.banner1);
Expand Down Expand Up @@ -56,9 +57,9 @@ protected void onCreate(Bundle savedInstanceState) {
break;
}
banner.setImages(images);//可以选择设置图片网址,或者资源文件,默认用Glide加载
banner.setOnBannerClickListener(new Banner.OnBannerClickListener() {//设置点击事件
banner.setOnBannerClickListener(new OnBannerClickListener() {//设置点击事件
@Override
public void OnBannerClick(View view, int position) {
public void OnBannerClick(int position) {
Toast.makeText(getApplicationContext(),"你点击了:"+position,Toast.LENGTH_LONG).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

public class Banner3Activity extends AppCompatActivity {
public class BannerCustomActivity extends AppCompatActivity {
private Banner banner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner3);
setContentView(R.layout.activity_banner_custom);
getSupportActionBar().setTitle(getIntent().getStringExtra("des"));
String[] images2= getResources().getStringArray(R.array.url2);
banner = (Banner) findViewById(R.id.banner3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.test.banner;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -13,19 +12,18 @@
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerClickListener;
import com.youth.banner.listener.OnLoadImageListener;

import java.util.Arrays;
import java.util.List;

public class Banner2Activity extends AppCompatActivity implements View.OnClickListener {
public class BannerSeniorActivity extends AppCompatActivity implements View.OnClickListener {
private Banner banner;
private Button refresh,stop,start;
boolean flag=true;
String[] images,images2,titles;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner2);
setContentView(R.layout.activity_banner_senior);
getSupportActionBar().setTitle(getIntent().getStringExtra("des"));
images= getResources().getStringArray(R.array.url);
images2= getResources().getStringArray(R.array.url2);
Expand All @@ -46,32 +44,28 @@ protected void onCreate(Bundle savedInstanceState) {
//设置轮播间隔时间
banner.setDelayTime(3000);
//设置动画
banner.setBannerAnimation(Transformer.ZoomIn);
//设置ViewPager的切换速度
banner.setScrollerTime(2000);
banner.setBannerAnimation(Transformer.CubeOut);
/**
* 可以选择设置图片网址,或者资源文件,默认用Glide加载
* 可以选择设置图片网址或者资源文件,默认用Glide加载
* 如果你想设置默认图片就在xml里设置default_image
* banner.setImages(images);
*/
//如果你想用自己项目的图片加载,那么----->自定义图片加载框架
banner.setImages(images, new Banner.OnLoadImageListener() {
banner.setImages(images, new OnLoadImageListener() {
@Override
public void OnLoadImage(ImageView view, Object url) {
/**
* 这里你可以根据框架灵活设置
*/
Glide.with(getApplicationContext())
.load(url)
.centerCrop()
.placeholder(R.mipmap.loading2)
.crossFade()
.into(view);
}
});
banner.setOnBannerClickListener(new Banner.OnBannerClickListener() {//设置点击事件
//设置点击事件
banner.setOnBannerClickListener(new OnBannerClickListener() {
@Override
public void OnBannerClick(View view, int position) {
public void OnBannerClick(int position) {
Toast.makeText(getApplicationContext(),"你点击了:"+position,Toast.LENGTH_LONG).show();
}
});
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/com/test/banner/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package com.test.banner;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;


Expand All @@ -37,10 +31,10 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == des.length - 1) {
startActivity(new Intent(this, Banner2Activity.class)
startActivity(new Intent(this, BannerSeniorActivity.class)
.putExtra("des", des[position]));
} else if (position == des.length - 2) {
startActivity(new Intent(this, Banner3Activity.class)
startActivity(new Intent(this, BannerCustomActivity.class)
.putExtra("des", des[position]));
} else {
startActivity(new Intent(this, BannerActivity.class)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<array name="url2">
<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>
<!--<item>http://img.zcool.cn/community/01996b57a7f6020000018c1bedef97.jpg</item>-->
<!--<item>http://img.zcool.cn/community/01700557a7f42f0000018c1bd6eb23.jpg</item>-->
</array>
<array name="title">
<item>51巅峰钜惠</item>
Expand Down
18 changes: 9 additions & 9 deletions banner/banner-banner.iml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,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/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" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<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" />
Expand All @@ -80,6 +72,14 @@
<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" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<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" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
Expand Down Expand Up @@ -107,8 +107,8 @@
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="glide-3.6.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
</component>
</module>
Loading

0 comments on commit eb49d45

Please sign in to comment.