RollPagerView的用法:android
/**
*
* @author smiling
* @date 2016/10
*/
Android Studio 導包:app
compile 'com.jude:rollviewpager:1.4.5'ide
佈局:佈局
<com.jude.rollviewpager.RollPagerView
android:layout_width="match_parent"
android:layout_height="180dp"
app:rollviewpager_play_delay="3000"/>this
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"spa
一般只須要設置play_delay。orm
程序:內存
//設置播放時間間隔
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 Control
mRollViewPager.pause()
mRollViewPager.resume()
mRollViewPager.isPlaying()get
Adapter:it
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; } }