国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android之ImageSwitcher的實例詳解

2019-12-12 02:11:31
字體:
來源:轉載
供稿:網友

Android之ImageSwitcher的實例詳解

一. 簡單示例

實例代碼:

public class AndroidUIActivity extends Activity {    // 當前顯示的圖片索引   private int index;    // 圖片數組   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);      // 全屏設置     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);      // 實現并設置工廠內部接口的makeView方法,用來顯示視圖。     is.setFactory(new ViewFactory() {        public View makeView() {         return new ImageView(AndroidUIActivity.this);       }     });      // 設置圖片來源     is.setImageResource(images[index]);      // 設置點擊監聽器     is.setOnClickListener(new View.OnClickListener() {        public void onClick(View v) {         // 點擊會切換圖片         index++;         if (index >= images.length) {           index = 0;         }         is.setImageResource(images[index]);       }     });      // 設置切入動畫     is.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(),         android.R.anim.slide_in_left));     // 設置切出動畫     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> 

二. 運行結果

啟動


點擊后切換過程

以上就是Android之ImageSwitcher的實例詳解,如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 方山县| 新蔡县| 滨海县| 夏津县| 卫辉市| 阿鲁科尔沁旗| 札达县| 东城区| 新邵县| 秦皇岛市| 迭部县| 黄梅县| 秦安县| 武夷山市| 甘洛县| 高雄县| 乌鲁木齐市| 文山县| 广平县| 石家庄市| 西丰县| 深圳市| 金沙县| 合江县| 新丰县| 繁峙县| 沐川县| 朝阳区| 丰城市| 南开区| 衡南县| 关岭| 荥经县| 平泉县| 东至县| 甘德县| 六枝特区| 宁南县| 桦川县| 栾川县| 海盐县|