1. AndroidImageSlider的使用:

参考源码:https://github.com/daimajia/AndroidImageSlider

当然网上介绍使用方法的很多,搜一搜。

2. 遇到的第一张闪过问题解决(其实我在想直接换一个其他的使用不久得了,但还是先解决了,再换)

* 导致这种问题的原因:(原因可能不是很详细,直接跳过看解决就好)

  在布局中使用SliderLayout,这样在数据未加载完成时,已经创建了对象。经过一番排查发现问题实在这里:

public SliderLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
LayoutInflater.from(context).inflate(R.layout.slider_layout, this, true); final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs,R.styleable.SliderLayout,
defStyle,0); mTransformerSpan = attributes.getInteger(R.styleable.SliderLayout_pager_animation_span, 1100);
mTransformerId = attributes.getInt(R.styleable.SliderLayout_pager_animation, Transformer.Default.ordinal());
mAutoCycle = attributes.getBoolean(R.styleable.SliderLayout_auto_cycle,true);
int visibility = attributes.getInt(R.styleable.SliderLayout_indicator_visibility,0);
for(PagerIndicator.IndicatorVisibility v: PagerIndicator.IndicatorVisibility.values()){
if(v.ordinal() == visibility){
mIndicatorVisibility = v;
break;
}
}
mSliderAdapter = new SliderAdapter(mContext);
PagerAdapter wrappedAdapter = new InfinitePagerAdapter(mSliderAdapter); mViewPager = (InfiniteViewPager)findViewById(R.id.daimajia_slider_viewpager);
mViewPager.setAdapter(wrappedAdapter); mViewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_UP:
recoverCycle();
break;
}
return false;
}
}); attributes.recycle();
setPresetIndicator(PresetIndicators.Center_Bottom);
setPresetTransformer(mTransformerId);
setSliderTransformDuration(mTransformerSpan,null);
setIndicatorVisibility(mIndicatorVisibility);
if(mAutoCycle){
startAutoCycle();
}
}

  创建了对象,就已经设置了Adapter,网络加载数据,导致时间延迟,加载完成,再设置Adapter时,会引发 ViewPagerEx 中的一个 PagerObserver 中的 onChanged() 方法引起的,具体是可以去看一下源码。了解了如何造成的,然并卵。直接 compile 进来的,你改不了源码。只能退而求其次。

* 解决方法:

我在加载完数据时再创建SliderLayout对象,进行数据填充,问题就解决了。这样就需要动态创建对象,并添加在相应的位置。之前那个位置,就可以用一个容器来代替。看代码:

private void initSliderLayout(List<PromotionsBean> promotionList) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
sliderLayout = new SliderLayout(getContext());
sliderLayout.setLayoutParams(params);
sliderLayout.requestLayout();
for (int i = 0; i < promotionList.size(); i++) {
final PromotionsBean promotionsBean = promotionList.get(i);
DefaultSliderView textSliderView = new DefaultSliderView(getContext());
// textSliderView.description(item.getInfo());//标题
textSliderView.image(promotionsBean.getImage());//加载图片
textSliderView.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
@Override
public void onSliderClick(BaseSliderView slider) {
Intent intent = new Intent(getContext(), WRTWebActivity.class);
intent.setAction(promotionsBean.getLink());
startActivity(intent);
}
});
sliderLayout.addSlider(textSliderView);
}
bannerRoot.addView(sliderLayout, 0); //bannerRoot 为容器
sliderLayout.startAutoCycle(4000, 4000, true);
}

  

AndroidImageSlider第一张图闪过的问题解决的更多相关文章

  1. PHP提取页面第一张图为缩略图的代码

    <?php $p = '/<img.*?src=[\'|\"](.+?)[\'|\"].*?>/i'; preg_match_all($p,$str,$match ...

  2. 通过三张图了解Redux中的重要概念

    上周利用业余的时间看了看Redux,刚开始有点不适应,一下在有了Action.Reducer.Store和Middleware这么多新的概念. 经过一些了解之后,发现Redux的单向数据里的模式还是比 ...

  3. 三张图让你高速明确activity与fragment生命周期的异同点

    第一张图:activity的生命周期 第二张图:fragment的生命周期 第三张图:activity与fragment生命周期对照 补充:假设你还是不明确,请翻译一下你不理解的相应单词. ----- ...

  4. 用两张图告诉你,为什么你的App会卡顿?

    有什么料? 从这篇文章中你能获得这些料: 知道setContentView()之后发生了什么? 知道Android究竟是如何在屏幕上显示我们期望的画面的? 对Android的视图架构有整体把握. 学会 ...

  5. jquery手写焦点轮播图-------解决最后一张无缝跳转第一张的问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 2.5w字 + 36 张图爆肝操作系统面试题,太牛逼了!

    欢迎各位大佬访问我的 github ,跪求 star bestJavaer 大家好,我是 cxuan,我之前汇总了一下关于操作系统的面试题,最近又重新翻阅了一下发现不是很全,现在也到了面试季了,所以我 ...

  7. 为了拿捏 Redis 数据结构,我画了 40 张图(完整版)

    大家好,我是小林. Redis 为什么那么快? 除了它是内存数据库,使得所有的操作都在内存上进行之外,还有一个重要因素,它实现的数据结构,使得我们对数据进行增删查改操作时,Redis 能高效的处理. ...

  8. 40张图+万字,从9个数据类型帮你稳稳的拿捏Redis数据结构

    摘要:本文把Redis新旧版本的数据结构说图解一遍,共有 9 种数据结构:SDS.双向链表.压缩列表.哈希表.跳表.整数集合.quicklist.listpack. 本文分享自华为云社区<为了拿 ...

  9. 深入理解javascript作用域系列第五篇——一张图理解执行环境和作用域

    × 目录 [1]图示 [2]概念 [3]说明[4]总结 前面的话 对于执行环境(execution context)和作用域(scope)并不容易区分,甚至很多人认为它们就是一回事,只是高程和犀牛书关 ...

随机推荐

  1. 结合sklearn的可视化工具Yellowbrick:超参与行为的可视化带来更优秀的实现

    https://blog.csdn.net/qq_34739497/article/details/80508262 Yellowbrick 是一套名为「Visualizers」的视觉诊断工具,它扩展 ...

  2. spring总结之一(spring开发步骤、bean对象的管理、bean生命周期)

    ###spring 1.概念:开源,轻量级,简化开发的企业级框架. 开源:免费,发展快. 轻量级:占内存小. 简化开发:通用的功能封装,提高程序员的开发效率.--------------------- ...

  3. Cannot assign “A1”: “B1” must be a “C1” instance.

    应用 django FORM 录入数据 必须 item_id supplier_id 不能item, supplier

  4. 理解 neutron

    之前大师发个结构图. understanding_neutron.pdf 自己走读了代码: 1.  get_extensions_path() # 在/opt/stack/neutron/neutro ...

  5. mysql 5.6二进制安装

    1.  进入用户家目录创建tools文件夹 # cd ~ #mkdir tools 2.下载MySQL5.6二进制包(搜狐镜像里有各版本下载http://mirrors.sohu.com/mysql/ ...

  6. python3 logging模块

    很多程序都有记录日志的需求,并且日志包含的信息有正常的程序访问日志还可能有错误,警告等信息输出,python的logging模块提供了标准的日志接口,可以通过它存储各种格式的日志,日志级别等级:cri ...

  7. 《linux内核设计分析》 第一周作业

    linux 基础入门 课程总结 一.linux系统简介 linux操作系统 整个计算机可以分为 硬件 内核 系统调用 应用程序 操作系统就属于内核和系统调用这两部分 操作系统历史发展 批处理操作系统 ...

  8. tf.nn.relu

    tf.nn.relu(features, name = None) 这个函数的作用是计算激活函数 relu,即 max(features, 0).即将矩阵中每行的非最大值置0. import tens ...

  9. Codeforces 808G Anthem of Berland - KMP - 动态规划

    题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字符串$s$,和一个字符串$t$,$t$只包含小写字母,$s$包含小写字母和通配符'?'.询问$t$可能在$s$中出现最多多少次. 原 ...

  10. Python 数据分析 - 索引和选择数据

    loc,iloc,ix三者间的区别和联系 loc .loc is primarily label based, but may also be used with a boolean array. 就 ...