效果如图所示
首先,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.p_w_picpathsliderdemo.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 .p_w_picpath(url) .setScaleType(BaseSliderView.ScaleType.Fit); sliderLayout.addSlider(customSliderView); } sliderLayout.setPresetTransformer(SliderLayout.Transformer.ZoomOut); sliderLayout.setCustomAnimation(new DescriptionAnimation()); sliderLayout.setDuration(2000); sliderLayout.setCustomIndicator(indicator); } }
当然可以根据需求而改动达到想要的效果
源码地址:http://down.51cto.com/data/2221974
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。