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'
}
<!-- if you want to load images from the internet -->
<uses-permission android:name="android.permission.INTERNET" /> <!-- if you want to load images from a file OR from the internet -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Step3:
Add the Slider to your layout:
xmlns:custom="http://schemas.android.com/apk/res-auto"
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
指示器
<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:pager_animation=”Accordion” 切换动画效果
custom:auto_cycle=”true” 自动播放
custom:indicator_visibility=”visible” 显示指示器
<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="200dp"/>
自定义指示器:
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_Magnifier_Oval_Black
用代码设置:
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.drawable.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);
AndroidImageSlider(图片轮播控件)的更多相关文章
- Android图片轮播控件
Android广告图片轮播控件,支持无限循环和多种主题,可以灵活设置轮播样式.动画.轮播和切换时间.位置.图片加载框架等! 使用步骤 Step 1.依赖banner Gradle dependenci ...
- Android-----------广告图片轮播控件
Banner广告图片轮播控件,支持无限循环和多种主题,可以灵活设置轮播样式.动画.轮播和切换时间.位置.图片加载框架等! 很多Android APP中都有广告栏,我也用过很多次了,特来写一篇博文. 先 ...
- 一起写一个Android图片轮播控件
注:本文提到的Android轮播控件Demo地址: Android图片轮播控件 1. 轮播控件的组成部分 我们以知乎日报Android客户端的轮播控件为例,分析一下轮播控件的主要组成: 首先我们要有用 ...
- Android 开发最牛的图片轮播控件,基本什么都包含了。
Android图片轮播控件 源码下载地址: Android 图片轮播 现在的绝大数app都有banner界面,实现循环播放多个广告图片和手动滑动循环等功能.因为ViewPager并不支持循环翻页, ...
- 第四十六篇、UICollectionView广告轮播控件
这是利用人的视觉错觉来实现无限轮播,UICollectionView 有很好的重用机制,这只是部分核心代码,后期还要继续完善和代码重构. #import <UIKit/UIKit.h> # ...
- Android之仿京东淘宝的自动无限轮播控件
在App的开发中,很多的时候都需要实现类似京东淘宝一样的自动无限轮播的广告栏,所以就自己写了一个,下面是我自定义控件的思路和过程. 一.自定义控件属性 新建自定义控件SliderLayout继承于Re ...
- Android高仿京东淘宝自动无限循环轮播控件的实现思路和过程
在App的开发中,很多的时候都需要实现类似京东淘宝一样的自动无限轮播的广告栏,所以就自己写了一个,下面是我自定义控件的实现思路和过程. 一.自定义控件属性 新建自定义控件SliderLayout继承于 ...
- Qt编写自定义控件24-图片轮播控件
一.前言 上一篇文章写的广告轮播控件,采用的传统widget堆积设置样式表做的,这次必须要用到更高级的QPainter来绘制了,这个才是最高效的办法,本控件参考雨田哥的轮播控件,经过大规模的改造而成, ...
- Qt编写自定义控件23-广告轮播控件
一.前言 广告轮播这个控件做的比较早,是很早以前定制一个电信客户端时候用到的,该客户端需要在首页展示轮播预先设定好的图片,图片的路径可以自由设定,然后轮播的间隔速度可以自由控制,同时该控件还需要提供两 ...
随机推荐
- spring boot: spring Aware的目的是为了让Bean获得Spring容器的服务
Spring Aware的目的是为了让Bean获得Spring容器的服务 //获取容器中的bean名称import org.springframework.beans.factory.BeanName ...
- uva 10917 最短路+dp
https://vjudge.net/problem/UVA-10917 给出N点M边的无向图,没重边.对于点A,B,当且仅当从B到终点的最短路小于任何一条从A到终点的最短路时,才考虑从A走到B,否则 ...
- codeforces C. Pearls in a Row map的应用
C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Android Studio 开始运行错误
/******************************************************************************** * Android Studio 开 ...
- CodeForces - 651D:Image Preview (双指针&)
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
- CodeForces - 138C: Mushroom Gnomes - 2 (线段树&概率&排序)
One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her th ...
- vue.js初学(一) vue的入门编程
1:首先引入vue.js 2:点击事件 <div id='clickVue'> <p>{{message}}</p> <button v-on:click=& ...
- 解决 No module named PyQt5.QtWebKitWidgets
原因:在 PyQt 5.6(+) 版本中, 新增 QtWebEngineWidgets 代替QtWebKitWidgets. 示例代码:#coding: utf-8 import sysfrom Py ...
- think python chapter3
3.1 built-in function type(42)=> <class 'int'> int('32')=>32 int(3.9) => 3 int(-2.3)= ...
- 在Mac系统下如何恢复SourceTree全局忽略的文件
在家目录“~”下编辑 “.gitignore_global ” 文件即可:vim .gitignore_global