Android之ImageSwitcher的實例詳解
更新時間:2017年08月24日 11:45:10 投稿:lqh
這篇文章主要介紹了Android之ImageSwitcher的實例詳解的相關(guān)資料,這里提供實例幫助大家理解這個控件的功能,希望能幫助到大家,需要的朋友可以參考下
Android之ImageSwitcher的實例詳解
一. 簡單示例
實例代碼:
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對象
final ImageSwitcher is = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
// 實現(xiàn)并設(shè)置工廠內(nèi)部接口的makeView方法,用來顯示視圖。
is.setFactory(new ViewFactory() {
public View makeView() {
return new ImageView(AndroidUIActivity.this);
}
});
// 設(shè)置圖片來源
is.setImageResource(images[index]);
// 設(shè)置點擊監(jiān)聽器
is.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 點擊會切換圖片
index++;
if (index >= images.length) {
index = 0;
}
is.setImageResource(images[index]);
}
});
// 設(shè)置切入動畫
is.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(),
android.R.anim.slide_in_left));
// 設(shè)置切出動畫
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>
二. 運行結(jié)果
啟動

點擊后切換過程

以上就是Android之ImageSwitcher的實例詳解,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
- Android入門之Gallery+ImageSwitcher用法實例解析
- 很贊的引導(dǎo)界面效果Android控件ImageSwitcher實現(xiàn)
- Android控件ImageSwitcher實現(xiàn)左右圖片切換功能
- Android常用控件ImageSwitcher使用方法詳解
- Android基于ImageSwitcher實現(xiàn)圖片切換功能
- Android UI控件之ImageSwitcher實現(xiàn)圖片切換效果
- Android高級組件ImageSwitcher圖像切換器使用方法詳解
- 基于Android實現(xiàn)保存圖片到本地并可以在相冊中顯示出來
- android獲取相冊圖片和路徑的實現(xiàn)方法
- Android ViewPager相冊橫向移動的實現(xiàn)方法
- Android開發(fā)之ImageSwitcher相冊功能實例分析
相關(guān)文章
Flutter?彈性布局基石flex算法flexible示例詳解
這篇文章主要為大家介紹了Flutter?彈性布局基石flex算法flexible示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12
Android中RecyclerView實現(xiàn)Item添加和刪除的代碼示例
本篇文章主要介紹了Android中RecyclerView實現(xiàn)Item添加和刪除的代碼示例,非常具有實用價值,需要的朋友可以參考下2017-09-09
android設(shè)置adb自帶screenrecord錄屏命令
這篇文章主要介紹了android設(shè)置adb自帶screenrecord錄屏命令,需要的朋友可以參考下2018-11-11
Android BottomNavigationView結(jié)合ViewPager實現(xiàn)底部導(dǎo)航欄步驟詳解
這篇文章主要介紹了Android BottomNavigationView結(jié)合ViewPager實現(xiàn)底部導(dǎo)航欄步驟,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02

