UltraViewPager
UltraViewPager是一个封装多种特性的ViewPager,主要是为多页面切换场景提供统一解决方案。
github地址
- 横向滑动
- 纵向滑动
- 支持一屏内显示多页
- 支持循环滚动
- 支持定时滚动,计时器使用Handler实现
- setRatio按比例显示UltraviewPager
- 内置indicator,只需简单设置几个属性就可以完成展示,支持圆点和Icon;
- 内置两种页面切换动效
- 以上特性支持同时使用;
展示一种比较独特的
<com.qw.dp.qwapplication.view.ultraviewpager.UltraViewPager
android:id="@+id/ultra_viewpager_DepthTransformer_Demo"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@android:color/white" />
private UltraViewPager ultra_viewpager_DepthTransformer_Demo;
ultra_viewpager_DepthTransformer_Demo = (UltraViewPager) findViewById(R.id.ultra_viewpager_DepthTransformer_Demo);
private void initDepthTransformer_Demo() {
ultra_viewpager_DepthTransformer_Demo.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL);
adapter = new UltraPagerAdapter(ViewPagerActivity.this);
ultra_viewpager_DepthTransformer_Demo.setAdapter(adapter);
ultra_viewpager_DepthTransformer_Demo.setMultiScreen(0.6f);
ultra_viewpager_DepthTransformer_Demo.setPageTransformer(false, new UltraDepthScaleTransformer());
//内置indicator初始化
ultra_viewpager_DepthTransformer_Demo.initIndicator();
//设置indicator样式
ultra_viewpager_DepthTransformer_Demo.getIndicator()
.setOrientation(UltraViewPager.Orientation.HORIZONTAL)
.setFocusColor(Color.GREEN)
.setNormalColor(Color.WHITE)
.setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));
//设置indicator对齐方式
ultra_viewpager_DepthTransformer_Demo.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
ultra_viewpager_DepthTransformer_Demo.getIndicator().setMargin(0,0,0,20);
//构造indicator,绑定到UltraViewPager
ultra_viewpager_DepthTransformer_Demo.getIndicator().build();
ultra_viewpager_DepthTransformer_Demo.setInfiniteLoop(true);
//设定页面自动切换 间隔2秒
ultra_viewpager_DepthTransformer_Demo.setAutoScroll(2000);
}
public class UltraPagerAdapter extends PagerAdapter {
private Context context;
public UltraPagerAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
return 5;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(container.getContext()).inflate(R.layout.layout_child, null);
ImageView iv = (ImageView) linearLayout.findViewById(R.id.iv);
linearLayout.setId(R.id.item_id);
iv.setId(R.id.item_id);
switch (position) {
case 0:
// linearLayout.setBackgroundColor(Color.parseColor("#2196F3"));
//Glide.with(context).load("http://img.taodiantong.cn/v55183/infoimg/2013-07/130720115322ky.jpg").into(iv);
Glide.with(context).load(R.drawable.home_banner_1).into(iv);
break;
case 1:
//Glide.with(context).load("http://pic30.nipic.com/20130626/8174275_085522448172_2.jpg").into(iv);
Glide.with(context).load(R.drawable.home_banner_1).into(iv);
// linearLayout.setBackgroundColor(Color.parseColor("#673AB7"));
break;
case 2:
//Glide.with(context).load("http://pic18.nipic.com/20111215/577405_080531548148_2.jpg").into(iv);
Glide.with(context).load(R.drawable.home_banner_1).into(iv);
// linearLayout.setBackgroundColor(Color.parseColor("#009688"));
break;
case 3: //Glide.with(context).load("http://pic15.nipic.com/20110722/2912365_092519919000_2.jpg").into(iv);
Glide.with(context).load(R.drawable.home_banner_1).into(iv);
// linearLayout.setBackgroundColor(Color.parseColor("#607D8B"));
break;
case 4: //Glide.with(context).load("http://pic.58pic.com/58pic/12/64/27/55U58PICrdX.jpg").into(iv);
Glide.with(context).load(R.drawable.home_banner_1).into(iv);
// linearLayout.setBackgroundColor(Color.parseColor("#F44336"));
break;
}
container.addView(linearLayout);
return linearLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
LinearLayout view = (LinearLayout) object;
container.removeView(view);
}
}
练手结束,上面是demo上的一些效果展示,down下代码好好研究吧,总有一款适合你的。