轮播图简单实现方式RollPagerView
android图片轮播效果,RollViewPager的简单使用
<com.jude.rollviewpager.RollPagerView android:id="@+id/mViewPager" android:layout_width="match_parent" android:layout_height="170dp" app:rollviewpager_play_delay="3000" />
在build.gradle(app)加载包
compile 'com.jude:rollviewpager:1.2.9'
实现代码:
//广告轮播 mViewPager = (RollPagerView) ItemView.findViewById(R.id.mViewPager); mViewPager.setAdapter(new ImageLoopAdapter(getActivity(), mViewPager));
ImageLoopAdapter.java
public class ImageLoopAdapter extends LoopPagerAdapter { String[] imgs = new String[0]; private Context mContext; public ImageLoopAdapter(Context mContext,RollPagerView viewPager) { super(viewPager); this.mContext = mContext; } @Override public View getView(ViewGroup container, int position) { ImageView view = new ImageView(container.getContext()); view.setScaleType(ImageView.ScaleType.CENTER_CROP); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); Glide.with(mContext).load(Constants.URL[position]).into(view); return view; } @Override public int getRealCount() { return Constants.URL.length; } }
添加图片数据源:
这里可以自己设定
public class Constants { public static String[] URL = { "http://cdn-l.llsapp.com/connett/c3115411-3669-466d-8ef2-e6c42c690303", "http://7xjww9.com1.z0.glb.clouddn.com/Hopetoun_falls.jpg", "http://cdn.llsapp.com/crm_test_1449051526097.jpg", }; }