安卓轮播组件
1.github的地址
https://github.com/daimajia/AndroidImageSlider
2.配置文件
//轮播插件 另外要一个v7的兼容包 api 'com.squareup.picasso:picasso:2.3.2' api 'com.nineoldandroids:library:2.4.0' api 'com.daimajia.slider:library:1.1.5@aar'
3.编写布局
<com.daimajia.slider.library.SliderLayout android:id="@+id/slider" android:layout_width="match_parent" android:layout_height="200dp" />
4.实际activity或者fragment ,记得destrory的时候要调用销毁轮播的方法,否则会内存溢出
public class MainActivity extends AppCompatActivity { SliderLayout sliderShow; private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initCarousel(); } private void initCarousel(){ sliderShow = (SliderLayout) findViewById(R.id.slider); TextSliderView textSliderView1 = new TextSliderView(this); textSliderView1 .image("http://i5qiniu.mtime.cn/mg/2016/12/04/143436.93575096.jpg"); textSliderView1.setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() { @Override public void onSliderClick(BaseSliderView slider) { Log.d(TAG, "onSliderClick: 123123"); } }); sliderShow.addSlider(textSliderView1); TextSliderView textSliderView2 = new TextSliderView(this); textSliderView2 .image("http://img5.mtime.cn/mg/2016/10/09/112424.73820873.jpg"); sliderShow.addSlider(textSliderView2); sliderShow.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom); } @Override protected void onStop() { sliderShow.stopAutoCycle(); super.onStop(); } }
5.实际显示效果