关闭

开源项目之AndroidImageSlider图片多姿势轮播

标签: android开源项目ImageSliderandroid studio
776人阅读 评论(0) 收藏 举报
分类:

转载请标明出处:http://blog.csdn.net/liu1252247624/article/details/51555361

效果如图所示

首先,Gradle中加入

compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5@aar'
 compile 'com.daimajia.androidanimations:library:1.1.3@aar'

然后添加权限

<!--需要访问网络图片则加上-->
<!--<uses-permission android:name="android.permission.INTERNET" />-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

因为我使用的是本地图片所以只加了一个

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:gravity="center"
    tools:context="com.lg.imagesliderdemo.MainActivity">

    <com.daimajia.slider.library.SliderLayout
        android:id="@+id/slider"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        custom:auto_cycle="true"
        custom:indicator_visibility="visible"
        custom:pager_animation="Accordion"
        custom:pager_animation_span="1100" />

    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/ind_pager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center" />
</RelativeLayout>

MainActivity中核心代码:

public class MainActivity extends AppCompatActivity {

    private SliderLayout sliderLayout;
    private PagerIndicator indicator;
    private int[] imgurl = new int[]{R.drawable.img_one,
            R.drawable.img_two, R.drawable.img_three, R.drawable.img_four};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        sliderLayout = (SliderLayout) findViewById(R.id.slider);
        indicator = (PagerIndicator) findViewById(R.id.ind_pager);
        for (int url : imgurl) {
            TextSliderView customSliderView = new TextSliderView(this);
            customSliderView
                    .image(url)
                    .setScaleType(BaseSliderView.ScaleType.Fit);
            sliderLayout.addSlider(customSliderView);
        }
        sliderLayout.setPresetTransformer(SliderLayout.Transformer.ZoomOut);
        sliderLayout.setCustomAnimation(new DescriptionAnimation());
        sliderLayout.setDuration(2000);
        sliderLayout.setCustomIndicator(indicator);
    }
}

当然可以根据需求而改动达到想要的效果

源码地址:http://download.csdn.net/detail/liu1252247624/9537666


2
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6176次
    • 积分:173
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:0篇
    • 译文:0篇
    • 评论:3条
    文章分类