RollPagerView的用法:
/** * * @author smiling * @date 2016/10 */
Android Studio 导包:
compile 'com.jude:rollviewpager:1.4.5'布局:
<com.jude.rollviewpager.RollPagerView
android:layout_width="match_parent" android:layout_height="180dp" app:rollviewpager_play_delay="3000"/>app:rollviewpager_play_delay = "3000" 单位是ms,默认是0。
app:rollviewpager_hint_gravity = "center" 中、左、右,默认中心。app:rollviewpager_hint_color = "#7c7c7c“ ,颜色指示器。默认是黑色的。app:rollviewpager_hint_alpha = "80"α为指标的container.0完全透明,255没有transparent.默认是0。app:rollviewpager_hint_paddingLeft = "16dp"填充指示器的容器app:rollviewpager_hint_paddingRight = "16dp "app:rollviewpager_hint_paddingTop = "16dp"app:rollviewpager_hint_paddingBottom = "16dp"通常只需要设置play_delay。
程序:
//设置播放时间间隔
mRollViewPager.setPlayDelay(3000);//设置透明度mRollViewPager.setAnimationDurtion(500);//设置适配器mRollViewPager.setAdapter(new TestAdapter());//设置指示器mRollViewPager.setHintView(new IconHintView(this,R.drawable.point_focus,R.drawable.point_normal));mRollViewPager.setHintView(new ColorPointHintView(this, Color.YELLOW,Color.WHITE));mRollViewPager.setHintView(new TextHintView(this));mRollViewPager.setHintView(null);//hide the indicator//Play ControlmRollViewPager.pause()mRollViewPager.resume()mRollViewPager.isPlaying()Adapter:
StaticPagerAdapter: 这个适配器将存储每一页(视图),一旦创建多次使用。可能会占用更多的内存。
DynamicPagerAdapter:这个适配器不会存储视图。它每次都创建新的视图。private class TestAdapter extends StaticPagerAdapter {
private int[] imgs = { R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, };@Override
public View getView(ViewGroup container, int position) { ImageView view = new ImageView(container.getContext()); view.setImageResource(imgs[position]); view.setScaleType(ImageView.ScaleType.CENTER_CROP); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //点击轮播图跳转到其他页面}
}); return view; } @Override public int getCount() { return imgs.length; } }