Android使用ViewFlipper實(shí)現(xiàn)圖片上下自動(dòng)輪播的示例代碼
本文主要介紹了Android使用ViewFlipper實(shí)現(xiàn)圖片上下自動(dòng)輪播的示例代碼,分享給大家,具體如下:
先看效果:<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)滾動(dòng)圖片的點(diǎn)擊事件 iv.setOnClickListener(listener); viewFlipper.addView(iv); viewFlipper.setAutoStart(true);}viewFlipper.setFlipInterval(3 * 1000);viewFlipper.startFlipping();
(2)輪播動(dòng)畫: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)圖片上下自動(dòng)輪播的示例代碼的文章就介紹到這了,更多相關(guān)Android 圖片上下自動(dòng)輪播內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. python excel和yaml文件的讀取封裝2. moment轉(zhuǎn)化時(shí)間戳出現(xiàn)Invalid Date的問(wèn)題及解決3. python爬蟲實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊4. Android Studio插件5. php實(shí)現(xiàn)當(dāng)前用戶在線人數(shù)6. Android中的緩存7. Python中內(nèi)建模塊collections如何使用8. Android組件化和插件化開發(fā)9. .net6 在中標(biāo)麒麟下的安裝和部署過(guò)程10. java——Byte類/包裝類的使用說(shuō)明
