Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile project(':library')
compile 'com.github.bumptech.glide:glide:3.6.1'
}
25 changes: 24 additions & 1 deletion app/src/main/java/com/yyydjk/sliderlayoutdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.yyydjk.library.BannerLayout;

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

public class MainActivity extends AppCompatActivity{
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -18,6 +20,27 @@ protected void onCreate(Bundle savedInstanceState) {

BannerLayout bannerLayout = (BannerLayout) findViewById(R.id.banner);
BannerLayout bannerLayout2 = (BannerLayout) findViewById(R.id.banner2);
//setListener必须在setViewUrls之前
bannerLayout.setListener(new BannerLayout.ImageSetListener() {
@Override
public void setImage(Object res, ImageView imageView, int defaultImage) {
if (defaultImage != 0) {
Glide.with(MainActivity.this).load(res).placeholder(defaultImage).centerCrop().into(imageView);
} else {
Glide.with(MainActivity.this).load(res).centerCrop().into(imageView);
}
}
});
bannerLayout2.setListener(new BannerLayout.ImageSetListener() {
@Override
public void setImage(Object res, ImageView imageView, int defaultImage) {
if (defaultImage != 0) {
Glide.with(MainActivity.this).load(res).placeholder(defaultImage).centerCrop().into(imageView);
} else {
Glide.with(MainActivity.this).load(res).centerCrop().into(imageView);
}
}
});

final List<String> urls = new ArrayList<>();
urls.add("http://img3.imgtn.bdimg.com/it/u=2674591031,2960331950&fm=23&gp=0.jpg");
Expand Down
1 change: 0 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
30 changes: 22 additions & 8 deletions library/src/main/java/com/yyydjk/library/BannerLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import android.widget.RelativeLayout;
import android.widget.Scroller;

import com.bumptech.glide.Glide;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -65,6 +63,16 @@ public class BannerLayout extends RelativeLayout {

private int defaultImage;

public ImageSetListener getListener() {
return listener;
}

public void setListener(ImageSetListener listener) {
this.listener = listener;
}

private ImageSetListener listener;

private int currentPosition;

private enum Shape {
Expand Down Expand Up @@ -207,7 +215,8 @@ public void onClick(View v) {
}
});
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Glide.with(getContext()).load(res).centerCrop().into(imageView);
listener.setImage(res, imageView, defaultImage);
// Glide.with(getContext()).load(res).centerCrop().into(imageView);
return imageView;
}

Expand Down Expand Up @@ -247,11 +256,12 @@ public void onClick(View v) {
}
});
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
if (defaultImage != 0){
Glide.with(getContext()).load(url).placeholder(defaultImage).centerCrop().into(imageView);
}else {
Glide.with(getContext()).load(url).centerCrop().into(imageView);
}
listener.setImage(url, imageView, defaultImage);
// if (defaultImage != 0){
// Glide.with(getContext()).load(url).placeholder(defaultImage).centerCrop().into(imageView);
// }else {
// Glide.with(getContext()).load(url).centerCrop().into(imageView);
// }
return imageView;
}

Expand Down Expand Up @@ -526,6 +536,10 @@ public void startScroll(int startX, int startY, int dx, int dy) {
super.startScroll(startX, startY, dx, dy, mDuration);
}
}

public interface ImageSetListener{
void setImage(Object res, ImageView imageView , int defaultImage);
}
}