需要引入的module下载链接:https://pan.baidu.com/s/1sdlQefBTfkLsNO__ouwz8w
添加module方法步骤:
(1)File----->New------>Import Module找到下载的banner文件
(2)app的build.gradle下的dependencies下添加
compile project(':banner')
//广告图
implementation 'com.youth.banner:banner:1.4.10'
xmlns:app="http://schemas.android.com/apk/res-auto"
图片加载工具方法:
public class GlideImageLoader extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
Glide.with(context)
.load(path)
.error(context.getResources().getDrawable(R.mipmap.img_banner))
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL))
.into(imageView);
}
}
mBanner.setImageLoader(new GlideImageLoader());
mBanner.setBannerAnimation(Transformer.Accordion);
mBanner.setOnBannerListener(this);
private List strings;
strings = Arrays.asList(dataBean.getImgs().split(","));
mBanner.setImages(strings);
mBanner.start();
如:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
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 'com.zxy.android:recovery:0.0.8'
compile project(':banner')
// compile 'com.youth.banner:banner:+'
}
(3)settings.gradle下添加‘banner’
include ':app',':banner'
.
(1)实现接口
public class MainActivity extends AppCompatActivity implements OnBannerListener {
(2)实现数据添加
banner.setIndicatorGravity(BannerConfig.LEFT);//指示器位置左中右
banner.updateBannerStyle(BannerConfig.NUM_INDICATOR);//标题显示与否,指示器显示与否
//简单使用
banner.setImages(App.images)//图片
.setBannerTitles(App.titles)//标题
.setImageLoader(new GlideImageLoader())
.setOnBannerListener(this)
.start();
(3)接口方法
@Override
public void OnBannerClick(int position) {//item图片点击
Toast.makeText(getApplicationContext(),"你点击了:"+position,Toast.LENGTH_SHORT).show();
}
implementation 'com.lakehubo:hbanner:1.0.8'
private HBanner banner;
private void init() {
banner.setBannerAnimation(Transformer.Default)//换场方式
.setBannerStyle(BannerStyle.CIRCLE_INDICATOR_TITLE)//指示器模式
.setCache(true)//可以不用设置,默认为true
.setCachePath(getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath() + File.separator + "hbanner")
.setVideoGravity(VideoGravityType.FULL_SCREEN)//视频布局方式
.setImageGravity(ImageGravityType.FIT_XY)//图片布局方式
.setPageBackgroundColor(Color.TRANSPARENT)//设置背景
.setShowTitle(false)//是否显示标题
.setViewPagerIsScroll(true)//是否支持手滑
.start();
List list2 = new ArrayList<>();
Uri path1 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.default1);
// Uri path2 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.default2);
String path2 = "http://gzlxcdg.app.xiaozhuschool.com/public/uploads/video/20200504/fa530b8ae53f8d2e7698ea0fb22d22d5.mp4";
list2.add(new ViewItemBean(VIDEO, "标题1", path1, 15 * 1000));
list2.add(new ViewItemBean(VIDEO, "标题2", path2, 18 * 1000));
list2.add(new ViewItemBean(IMAGE, "标题3", R.mipmap.b2, 2 * 1000));
banner.update(list2);
}
依赖
//glide implementation 'com.github.bumptech.glide:glide:4.9.0'
//图文混播 implementation 'com.github.licheedev:AdPlayer:1.0.2'
AdView ad; private AdPlayermAdPlayer;
ad = (AdView) findViewById(R.id.ad); mAdPlayer = new AdPlayer<>(ad);
String urlll = "https://gzlxcdg.https.xiaozhuschool.com/public/uploads/imgs/20200306/b23d77407c27feb9ffdc578158784589.png"; String vds = "https://gzlxcdg.https.xiaozhuschool.com/public/uploads/video/20200504/fa530b8ae53f8d2e7698ea0fb22d22d5.mp4"; String vds2 = "https://gzlxcdg.https.xiaozhuschool.com/public/uploads/imgs/20200411/6329153ceb93a706fe62abdec9cbbe57.jpeg"; Listurls = new ArrayList<>(); urls.add(urlll); urls.add(vds); urls.add(vds2); mAdPlayer.setNewData(UrlAdData.convert(urls));
@Override public void onResume() { super.onResume(); mAdPlayer.resume(); } @Override public void onPause() { super.onPause(); mAdPlayer.pause(); } @Override public void onDestroy() { mAdPlayer.release(); super.onDestroy(); }