Skip to content

Commit

Permalink
demo中增加本地图片加载例子
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Dec 22, 2016
1 parent 90d7cd0 commit b5b6ff5
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected void onStop() {
//sd卡资源
String[] images={"file://"+ Environment.getExternalStorageDirectory().getPath()+"/test.jpg"};

banner.setImages(images);//这里接收数组和集合都行
banner.setImages(images);//这里接收集合,上面写成集合太占地方,这个大家举一反三就行了啊
```

* 问:设置banner指示器颜色怎么变成方的了?
Expand Down
16 changes: 8 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/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 @@ -81,6 +73,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/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<activity android:name=".demo.BannerAnimationActivity" />
<activity android:name=".demo.BannerStyleActivity" />
<activity android:name=".demo.IndicatorPositionActivity" />
<activity android:name=".demo.CustomBannerActivity"></activity>
<activity android:name=".demo.CustomBannerActivity" />
<activity android:name=".demo.BannerLocalActivity"></activity>
</application>

</manifest>
4 changes: 3 additions & 1 deletion app/src/main/java/com/test/banner/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ public class App extends Application {
public static List<?> images=new ArrayList<>();
public static List<String> titles=new ArrayList<>();
public static int H;
public static App app;
@Override
public void onCreate() {
super.onCreate();
app=this;
H=getScreenH(this);
Fresco.initialize(this);
Recovery.getInstance()
Expand All @@ -27,7 +29,7 @@ public void onCreate() {
.recoverStack(true)
.mainPage(MainActivity.class)
.init(this);
String[] urls = getResources().getStringArray(R.array.url4);
String[] urls = getResources().getStringArray(R.array.url);
String[] tips = getResources().getStringArray(R.array.title);
List list = Arrays.asList(urls);
images = new ArrayList(list);
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/test/banner/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.widget.Toast;

import com.test.banner.demo.BannerAnimationActivity;
import com.test.banner.demo.BannerLocalActivity;
import com.test.banner.demo.BannerStyleActivity;
import com.test.banner.demo.CustomBannerActivity;
import com.test.banner.demo.IndicatorPositionActivity;
Expand All @@ -37,7 +38,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case REFRESH_COMPLETE:
String[] urls = getResources().getStringArray(R.array.url);
String[] urls = getResources().getStringArray(R.array.url4);
List list = Arrays.asList(urls);
List arrayList = new ArrayList(list);
banner.update(arrayList);
Expand Down Expand Up @@ -113,6 +114,9 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
case 4:
startActivity(new Intent(this, CustomBannerActivity.class));
break;
case 5:
startActivity(new Intent(this, BannerLocalActivity.class));
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.Arrays;
import java.util.List;

public class BannerAnimationActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
public class BannerAnimationActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, OnBannerClickListener {
Banner banner;
List<Class<? extends ViewPager.PageTransformer>> transformers=new ArrayList<>();
public void initData(){
Expand Down Expand Up @@ -78,6 +78,7 @@ protected void onCreate(Bundle savedInstanceState) {

banner.setImages(App.images)
.setImageLoader(new GlideImageLoader())
.setOnBannerClickListener(this)
.start();

}
Expand All @@ -86,4 +87,10 @@ protected void onCreate(Bundle savedInstanceState) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
banner.setBannerAnimation(transformers.get(position));
}

@Override
public void OnBannerClick(int position) {
Log.e("--",position+"");
Toast.makeText(getApplicationContext(),"你点击了:"+position,Toast.LENGTH_SHORT).show();
}
}
39 changes: 39 additions & 0 deletions app/src/main/java/com/test/banner/demo/BannerLocalActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.test.banner.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.test.banner.App;
import com.test.banner.R;
import com.test.banner.loader.GlideImageLoader;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

public class BannerLocalActivity extends AppCompatActivity {

Banner banner;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner_local);
initView();
}

private void initView() {
banner = (Banner) findViewById(R.id.banner);
//本地图片数据(资源文件)
List<Integer> list=new ArrayList<>();
list.add(R.mipmap.b1);
list.add(R.mipmap.b2);
list.add(R.mipmap.b3);



banner.setImages(list)
.setImageLoader(new GlideImageLoader())
.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

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


public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择
Glide.with(context)
Glide.with(context.getApplicationContext())
.load(path)
.crossFade()
.into(imageView);
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_banner_local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.youth.banner.Banner xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="200dp"
app:indicator_drawable_selected="@drawable/selected_radius"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="
第三方加载器一般都支持(资源文件、文件、Uri、assets、raw、ContentProvider、sd卡资源)
这里只是以glide举例加载本地(资源文件)图片,
加载本地图片的具体方法请参考你使用的图片加载器,
图片加载的链接格式是你在setImages时设置的格式,
原样返回的,所以格式问题请仔细检查!"/>
</LinearLayout>
Binary file added app/src/main/res/mipmap-xhdpi/b1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/b2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/b3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 7 additions & 9 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="url">
<item>http://img.zcool.cn/community/01d28457d621800000018c1bb7877e.jpg</item>
<item>http://img.zcool.cn/community/01ae5656e1427f6ac72531cb72bac5.jpg</item>
<item>http://img.zcool.cn/community/0166c756e1427432f875520f7cc838.jpg</item>
<item>http://img.zcool.cn/community/018fdb56e1428632f875520f7b67cb.jpg</item>
<item>http://img.zcool.cn/community/01c8dc56e1428e6ac72531cbaa5f2c.jpg</item>
<item>http://img.zcool.cn/community/01fd2756e142716ac72531cbf8bbbf.jpg</item>
<item>http://img.zcool.cn/community/0192a557a352ef0000012e7ed104e4.jpg</item>
<item>http://ww4.sinaimg.cn/large/006uZZy8jw1faic1xjab4j30ci08cjrv.jpg</item>
<item>http://ww4.sinaimg.cn/large/006uZZy8jw1faic21363tj30ci08ct96.jpg</item>
<item>http://ww4.sinaimg.cn/large/006uZZy8jw1faic259ohaj30ci08c74r.jpg</item>
<item>http://ww4.sinaimg.cn/large/006uZZy8jw1faic2b16zuj30ci08cwf4.jpg</item>
<item>http://ww4.sinaimg.cn/large/006uZZy8jw1faic2e7vsaj30ci08cglz.jpg</item>
</array>

<array name="url1">
<item>http://img.zcool.cn/community/01700557a7f42f0000018c1bd6eb23.jpg</item>
</array>
Expand All @@ -28,14 +27,13 @@
<item>生命不是要超越别人,而是要超越自己。</item>
<item>己所不欲,勿施于人。——孔子</item>
<item>嗨购5折不要停</item>
<item>以诚感人者,人亦诚而应。</item>
<item>习惯改变命运,细节铸就终身。</item>
</array>
<array name="demo_list">
<item>banner动画预览</item>
<item>banner内置样式预览</item>
<item>banner指示器位置设置预览</item>
<item>banner一些自定义样式方法预览</item>
<item>banner加载本地图片</item>
<item>!!banner更多用法请看文档,这里就不一一列举了!</item>
</array>
<array name="anim">
Expand Down

0 comments on commit b5b6ff5

Please sign in to comment.