Android使用ViewFlipper實(shí)現(xiàn)圖片上下自動輪播的示例代碼
本文主要介紹了Android使用ViewFlipper實(shí)現(xiàn)圖片上下自動輪播的示例代碼,分享給大家,具體如下:
先看效果:<ViewFlipper android: android:layout_width='match_parent' android:layout_height='match_parent' android:flipInterval='3000' android:inAnimation='@anim/anim_marquee_in' android:outAnimation='@anim/anim_marquee_out' />2.具體實(shí)現(xiàn):
(1)關(guān)鍵代碼:
// 輪播的圖片集合List<String> picList; //......................//..........此處省去初始化picList...... //......................viewFlipper.removeAllViews();for (int i = 0; i < picList.size(); i++) { final String pic = picList.get(i); // 此處可以換成自己自定義的布局,根據(jù)需求 ImageView iv = new ImageView(context); iv.setImageResource(R.mipmap.bg); // 循環(huán)滾動圖片的點(diǎn)擊事件 iv.setOnClickListener(listener); viewFlipper.addView(iv); viewFlipper.setAutoStart(true);}viewFlipper.setFlipInterval(3 * 1000);viewFlipper.startFlipping();
(2)輪播動畫:android:inAnimation + android:outAnimation
anim_marquee_in
<?xml version='1.0' encoding='utf-8'?><set xmlns:android='http://schemas.android.com/apk/res/android'> <translateandroid:duration='1500'android:fromYDelta='100%p'android:toYDelta='0'/></set>
anim_marquee_out
<?xml version='1.0' encoding='utf-8'?><set xmlns:android='http://schemas.android.com/apk/res/android'> <translateandroid:duration='1500'android:fromYDelta='0'android:toYDelta='-100%p'/></set>
到此這篇關(guān)于Android使用ViewFlipper實(shí)現(xiàn)圖片上下自動輪播的示例代碼的文章就介紹到這了,更多相關(guān)Android 圖片上下自動輪播內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
