android轮播图AndroidImageSlider的简单使用
2017-02-22 11:37
113 查看
网上关于轮播图的博客鱼龙混杂,我用的较多的是AndroidImageSlider这个开源库,该项目是国外非常出名的开源项目,官方github地址 https://github.com/daimajia/AndroidImageSlider
AndroidImageSlider的架构,最核心的类是SliderLayout,,继承RelativeLayout。
包含了可以左右滑动切换的SliderView,以及页面指示器PagerIndicator,也就是上图中的4个小圆点。这两个都可以自定义,常规的用法是:使用TextSliderView+自定义PagerIndicator
一、使用
参考GithHub中AndroidImageSlider主页的介绍,首先将需要的三个依赖项目引入进来,他们分别是:(版本是楠妹妹写这个笔记的时候的最新版)
1、添加依赖
2、引入布局
//custom:pager_animation=”Accordion” 切换动画效果
//custom:auto_cycle=”true” 自动播放
//custom:indicator_visibility=”visible” 显示指示器
新建指示器布局 layout_Indicator.xml
自定义指示器:
custom:shape=”oval” 或 rect 圆形,矩形
style的三种默认参数AndroidImageSlider_Corner_Oval_Orange,AndroidImageSlider_Attractive_Rect_Blue,AndroidImageSlider_M
3、最后在代码中操作:
本文借鉴了“没有失败,没有放弃”的对该项目的理解的一些想法,如有不妥,可告知,将妥善处理。
引用博客地址http://www.cnblogs.com/java-g/p/5690703.html
AndroidImageSlider的架构,最核心的类是SliderLayout,,继承RelativeLayout。
包含了可以左右滑动切换的SliderView,以及页面指示器PagerIndicator,也就是上图中的4个小圆点。这两个都可以自定义,常规的用法是:使用TextSliderView+自定义PagerIndicator
一、使用
参考GithHub中AndroidImageSlider主页的介绍,首先将需要的三个依赖项目引入进来,他们分别是:(版本是楠妹妹写这个笔记的时候的最新版)
1、添加依赖
dependencies { compile "com.android.support:support-v4:+" compile 'com.squareup.picasso:picasso:2.3.2' compile 'com.nineoldandroids:library:2.4.0' compile 'com.daimajia.slider:library:1.1.5@aar' }
2、引入布局
<com.daimajia.slider.library.SliderLayout android:id="@+id/slider1" android:layout_width="match_parent" custom:pager_animation="Accordion" custom:auto_cycle="true" custom:indicator_visibility="visible" custom:pager_animation_span="1100" android:layout_height="180dp"/>
//custom:pager_animation=”Accordion” 切换动画效果
//custom:auto_cycle=”true” 自动播放
//custom:indicator_visibility=”visible” 显示指示器
新建指示器布局 layout_Indicator.xml
<com.daimajia.slider.library.Indicators.PagerIndicator android:id="@+id/custom_indicator" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"/>
自定义指示器:
custom:shape=”oval” 或 rect 圆形,矩形
<com.daimajia.slider.library.Indicators.PagerIndicator android:id="@+id/custom_indicator" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" custom:selected_color="#0095BF" custom:unselected_color="#55333333" custom:selected_drawable="@drawable/bird" custom:shape="oval" custom:selected_padding_left="5dp" custom:selected_padding_right="5dp" custom:unselected_padding_left="5dp" custom:unselected_padding_right="5dp" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" custom:selected_width="6dp" custom:selected_height="6dp" custom:unselected_width="6dp" custom:unselected_height="6dp" android:layout_marginBottom="40dp" /> <!-- style 在lib里面 --> <com.daimajia.slider.library.Indicators.PagerIndicator android:id="@+id/custom_indicator2" style="@style/AndroidImageSlider_Corner_Oval_Orange" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:layout_marginBottom="20dp" />
style的三种默认参数AndroidImageSlider_Corner_Oval_Orange,AndroidImageSlider_Attractive_Rect_Blue,AndroidImageSlider_M
3、最后在代码中操作:
private SliderLayout mDemoSlider1; mDemoSlider1 = (SliderLayout)findViewById(R.id.slider1); HashMap<String,String> url_maps = new HashMap<String, String>(); url_maps.put("Hannibal", "http://static2.hypable.com/wp-content/uploads/2013/12/hannibal-season-2-release-date.jpg"); url_maps.put("Big Bang Theory", "http://tvfiles.alphacoders.com/100/hdclearart-10.png"); url_maps.put("House of Cards", "http://cdn3.nflximg.net/images/3093/2043093.jpg"); url_maps.put("Game of Thrones", "http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg"); // HashMap<String,Integer> file_maps = new HashMap<String, Integer>(); // file_maps.put("Hannibal",R.drawable.nemo); // file_maps.put("Big Bang Theory",R.drawable.up); // file_maps.put("House of Cards",R.drawable.wall); // file_maps.put("Game of Thrones", R.drawa 4000 ble.toystory); for(String name : url_maps.keySet()){ // DefaultSliderView sliderView = new DefaultSliderView(this); TextSliderView textSliderView = new TextSliderView(this); // initialize a SliderLayout textSliderView .description(name) .image(url_maps.get(name)) .setScaleType(BaseSliderView.ScaleType.Fit) .setOnSliderClickListener(this); //add your extra information 点击图片时可用到 textSliderView.bundle(new Bundle()); textSliderView.getBundle() .putString("extra",name); mDemoSlider1.addSlider(textSliderView); } // 设置默认过渡效果(可在xml中设置) //mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Default); mDemoSlider1.setPresetTransformer(SliderLayout.Transformer.Accordion); // 设置默认指示器位置(默认指示器白色,位置在sliderlayout底部) mDemoSlider1.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom); // 设置自定义指示器(位置自定义) mDemoSlider1.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator)); // 设置TextView自定义动画 mDemoSlider1.setCustomAnimation(new DescriptionAnimation()); //mDemoSlider2.setCustomAnimation(new ChildAnimationExample()); // 多种效果,进入该类修改,参考效果github/daimajia/AndroidViewAnimations // 设置持续时间 mDemoSlider1.setDuration(2000); mDemoSlider1.addOnPageChangeListener(this);
本文借鉴了“没有失败,没有放弃”的对该项目的理解的一些想法,如有不妥,可告知,将妥善处理。
引用博客地址http://www.cnblogs.com/java-g/p/5690703.html
相关文章推荐
- android开发之&使用viewFlipper实现轮播图,超级简单
- android图片轮播效果,RollViewPager的简单使用
- android图片加文字轮播效果,RollViewPager使用,简单修改源代码
- android图片轮播效果,RollViewPager的简单使用
- 5.轮播广告AndroidImageSlider的使用(包括自定义indicator,和sliderview的点击监听事件,架构分析)
- android图片轮播效果,RollViewPager的简单使用(跑马灯)
- android图片轮播效果,RollViewPager的简单使用
- 使用AndroidImageSlider实现轮播
- [置顶] Android图片轮播控件ConvenientBanner的简单使用
- android图片轮播效果,RollViewPager的简单使用
- [置顶] Android图片轮播控件ConvenientBanner的简单使用
- android 图片轮播控件 Android-ConvenientBanner简单使用
- Android中的ViewFlipper的简单使用------自动轮播
- android图片轮播效果,开源框架RollViewPager的简单使用
- Android 图片轮播效果,RollViewPager的简单使用
- android图片轮播效果,RollViewPager的简单使用
- android图片轮播效果,RollViewPager的简单使用
- android图片轮播效果,RollViewPager的简单使用 原创 2016年05月06日 09:48:54 标签: android / RollViewPager 图
- android图片轮播效果,RollViewPager的简单使用
- android图片轮播效果,RollViewPager的简单使用(跑马灯)