您好,登錄后才能下訂單哦!
效果如圖所示
首先,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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。