android 图片轮播com.daimajia.slider.library.SliderLayout注意事项

1.在build文件中进行配置

      // 图片框架 https://github.com/square/picasso
    compile 'com.squareup.picasso:picasso:2.5.2'
    // 动画兼容框架 https://github.com/JakeWharton/NineOldAndroids
    compile 'com.nineoldandroids:library:2.4.0'
    // 广告横幅 https://github.com/daimajia/AndroidImageSlider
    compile 'com.daimajia.slider:library:1.1.5@aar'
2.权限 
 
  

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 
  
3.引导页效果
UI:
<com.daimajia.slider.library.SliderLayout
    android:id="@+id/slider"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:auto_cycle="false"/>
 
  
 
  
<com.daimajia.slider.library.Indicators.PagerIndicator
    android:id="@+id/custom_indicator"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    custom:selected_color="#FF5500"
    custom:unselected_color="#55333333"
    custom:shape="rect"
    custom:selected_padding_left="2dp"
    custom:selected_padding_right="2dp"
    custom:unselected_padding_left="2dp"
    custom:unselected_padding_right="2dp"
    custom:selected_width="16dp"
    custom:selected_height="3dp"
    custom:unselected_width="16dp"
    custom:unselected_height="3dp"
    android:layout_gravity="center"
    />

后台代码:
 
  
@ContentView(R.layout.activity_launcher_guide)
public class LauncherGuideActivity extends BaseActivity {

    @ViewInject(R.id.slider)
    private SliderLayout slider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PagerIndicator indicator = slider.getPagerIndicator();
        indicator.setDefaultIndicatorColor(0xffffffff, 0x80ffffff);
        indicator.setDefaultSelectedIndicatorSize(12f, 12f, PagerIndicator.Unit.DP);
        indicator.setDefaultUnselectedIndicatorSize(8f, 8f, PagerIndicator.Unit.DP);

        slider.addSlider(new DefaultSliderView(this).setScaleType(BaseSliderView.ScaleType.CenterCrop).empty(R.color.colorGuide1).image(R.mipmap.bg_guide_1));
        slider.addSlider(new DefaultSliderView(this).setScaleType(BaseSliderView.ScaleType.CenterCrop).empty(R.color.colorGuide2).image(R.mipmap.bg_guide_2));
        slider.addSlider(new DefaultSliderView(this).setScaleType(BaseSliderView.ScaleType.CenterCrop).empty(R.color.colorGuide3).image(R.mipmap.bg_guide_3));
// 设置默认过渡效果(可在xml中设置)      
slider.setPresetTransformer(SliderLayout.Transformer.Accordion);
        // 设置默认指示器位置(默认指示器白色,位置在sliderlayout底部)       
slider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        // 设置自定义指示器(位置自定义)
        slider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator));
        // 设置TextView自定义动画
        slider.setCustomAnimation(new DescriptionAnimation());
        //slider.setCustomAnimation(new ChildAnimationExample()); // 多种效果,进入该类修改,参考效果github/daimajia/AndroidViewAnimations
        // 设置持续时间
        slider.setDuration(2000);
        slider.addOnPageChangeListener(this);
       slider.addSlider(new DefaultSliderView(LauncherGuideActivity.this).empty(R.color.colorDark80).image(R.color.colorDark80));
                slider.setCurrentPosition(0);
                try {
                    Field fieldViewPager = SliderLayout.class.getDeclaredField("mViewPager");
                    Field fieldSliderAdapter = SliderLayout.class.getDeclaredField("mSliderAdapter");
                    fieldViewPager.setAccessible(true);
                    fieldSliderAdapter.setAccessible(true);
                    InfiniteViewPager mViewPager = (InfiniteViewPager) fieldViewPager.get(slider);
                    final SliderAdapter mSliderAdapter = (SliderAdapter) fieldSliderAdapter.get(slider);
                    mViewPager.setAdapter(new InfinitePagerAdapter(mSliderAdapter) {
                        @Override
                        public int getCount() {
                            return getRealCount();
                        }

                    });
                    slider.addOnPageChangeListener(new PagerIndicator(LauncherGuideActivity.this) {
                        @Override
                        public void onPageSelected(int position) {
                            super.onPageSelected(position);
                            if (position == mSliderAdapter.getCount() - 1) {
                                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                                finish();
                            }
                        }
                    });
                } catch (Exception e) {
                    LogHelper.e("GuideActivity.initViews", e);
                }
}}
4.首页轮播图效果
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.daimajia.slider.library.SliderLayout
        android:id="@+id/slider"
        android:layout_width="match_parent"
        android:layout_height="144dp"/>

FrameLayout>

你可能感兴趣的:(Android)