Android之ImageSwitcher的實(shí)例詳解
Android之ImageSwitcher的實(shí)例詳解
一. 簡(jiǎn)單示例
實(shí)例代碼:
public class AndroidUIActivity extends Activity { // 當(dāng)前顯示的圖片索引 private int index; // 圖片數(shù)組 private int[] images = { R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5 }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 全屏設(shè)置 requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); // 得到ImageSwitcher對(duì)象 final ImageSwitcher is = (ImageSwitcher) findViewById(R.id.imageSwitcher1); // 實(shí)現(xiàn)并設(shè)置工廠內(nèi)部接口的makeView方法,用來(lái)顯示視圖。 is.setFactory(new ViewFactory() { public View makeView() { return new ImageView(AndroidUIActivity.this); } }); // 設(shè)置圖片來(lái)源 is.setImageResource(images[index]); // 設(shè)置點(diǎn)擊監(jiān)聽(tīng)器 is.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // 點(diǎn)擊會(huì)切換圖片 index++; if (index >= images.length) { index = 0; } is.setImageResource(images[index]); } }); // 設(shè)置切入動(dòng)畫(huà) is.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.slide_in_left)); // 設(shè)置切出動(dòng)畫(huà) is.setOutAnimation(AnimationUtils.loadAnimation( getApplicationContext(), android.R.anim.slide_out_right)); } }
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageSwitcher android:id="@+id/imageSwitcher1" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageSwitcher> </LinearLayout>
二. 運(yùn)行結(jié)果
啟動(dòng)
點(diǎn)擊后切換過(guò)程
以上就是Android之ImageSwitcher的實(shí)例詳解,如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Android入門(mén)之Gallery+ImageSwitcher用法實(shí)例解析
- 很贊的引導(dǎo)界面效果Android控件ImageSwitcher實(shí)現(xiàn)
- Android控件ImageSwitcher實(shí)現(xiàn)左右圖片切換功能
- Android常用控件ImageSwitcher使用方法詳解
- Android基于ImageSwitcher實(shí)現(xiàn)圖片切換功能
- Android UI控件之ImageSwitcher實(shí)現(xiàn)圖片切換效果
- Android高級(jí)組件ImageSwitcher圖像切換器使用方法詳解
- 基于Android實(shí)現(xiàn)保存圖片到本地并可以在相冊(cè)中顯示出來(lái)
- android獲取相冊(cè)圖片和路徑的實(shí)現(xiàn)方法
- Android ViewPager相冊(cè)橫向移動(dòng)的實(shí)現(xiàn)方法
- Android開(kāi)發(fā)之ImageSwitcher相冊(cè)功能實(shí)例分析
相關(guān)文章
Kotlin?Navigation可視化開(kāi)發(fā)詳解
Navigation?是?JetPack?中的一個(gè)組件,用于方便的實(shí)現(xiàn)頁(yè)面的導(dǎo)航,所以抽象出了一個(gè)?destination?的概念,大部分情況一個(gè)?destination?就表示一個(gè)?Fragment,但是它同樣可以指代?Activity、其它的導(dǎo)航圖2023-02-02百度地圖實(shí)現(xiàn)小車(chē)規(guī)劃路線后平滑移動(dòng)功能
這篇文章主要介紹了百度地圖實(shí)現(xiàn)小車(chē)規(guī)劃路線后平滑移動(dòng)功能,本文是小編寫(xiě)的一個(gè)demo,通過(guò)效果圖展示的非常直白,需要的朋友可以參考下2020-01-01Android設(shè)計(jì)模式之單例模式實(shí)例
這篇文章主要介紹了Android設(shè)計(jì)模式之單例模式實(shí)例,單例模式是運(yùn)用最廣泛的設(shè)計(jì)模式之一,在應(yīng)用這個(gè)模式時(shí),單例模式的類(lèi)必須保證只有一個(gè)實(shí)例存在2023-04-04Android自定義View之自定義評(píng)價(jià)打分控件RatingBar實(shí)現(xiàn)自定義星星大小和間距
Android開(kāi)發(fā)中,我們經(jīng)常會(huì)用到對(duì)商家或者商品的評(píng)價(jià),運(yùn)用星星進(jìn)行打分。這篇文章介紹了Android自定義View之自定義評(píng)價(jià)打分控件RatingBar可以自定義星星大小和間距的相關(guān)資料,感興趣的朋友一起看看吧2016-10-10Android實(shí)現(xiàn)底部滾輪式選擇彈跳框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)底部滾輪式選擇彈跳框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08android實(shí)現(xiàn)簡(jiǎn)單的畫(huà)畫(huà)板實(shí)例代碼
畫(huà)畫(huà)板實(shí)現(xiàn)起來(lái)其實(shí)很簡(jiǎn)單,我們只需要利用android給我們提供的Canvas類(lèi)來(lái)操作就可以實(shí)現(xiàn)簡(jiǎn)單的畫(huà)畫(huà)功能2014-01-01Android 中 GridView嵌套在ScrollView里只有一行的解決方法
本文給大家?guī)?lái)兩種有關(guān)Android 中 GridView嵌套在ScrollView里只有一行的解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-10-10