(android控制項)ImageSwitcher介紹和使用說明

來源:互聯網
上載者:User

1   ImageSwitcher實現的功能 和實際啟動並執行示意

ImageSwitcher類提供了圖片切換功能,通過第三方的操作,設定當前ImageSwitcher顯示的圖片,同時設定圖片變換的動畫。

 

如何使用ImageSwitcher控制項

 

2.1 配置分頁檔

     <ImageSwitcher

            android:id="@+id/imageSwitcher1"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:layout_alignLeft="@+id/textView1"

            android:layout_above="@id/adLayout"

            android:layout_below="@id/topText"

            android:layout_centerVertical="true" >

        </ImageSwitcher>

 

初始化ImageSwitcher控制項

 初始化ViewPager控制項的適配器

 

imageSwitcher1 = (ImageSwitcher) findViewById(R.id.imageSwitcher1);

        imageSwitcher1.setFactory(this);

        imageSwitcher1.setInAnimation(AnimationUtils.loadAnimation(this,

                android.R.anim.fade_in));

        imageSwitcher1.setOutAnimation(AnimationUtils.loadAnimation(this,

                android.R.anim.fade_out));

   

      imageSwitcher1.setImageResource(R.drawable.girl2);

 

4 根據介面滑動的方向切換圖片

OnTouchListener touchlistener = new OnTouchListener() { 

          

        @Override 

        public boolean onTouch(View v, MotionEvent event) { 

            if (event.getAction() == MotionEvent.ACTION_DOWN) { 

                downX = (int) event.getX();

                return true

            } else if (event.getAction() == MotionEvent.ACTION_UP) { 

                upX = (int) event.getX();

                if (upX - downX > 100) {

                

                    imageSwitcher1.setInAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

                            android.R.anim.slide_in_left));

                    imageSwitcher1.setOutAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

                            android.R.anim.slide_out_right));

                    imageSwitcher1.setImageResource(R.drawable.girl1);

                   

                } else if (downX - upX > 100)//                { 

               

                    imageSwitcher1.setInAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

                            android.R.anim.slide_in_left));

                    imageSwitcher1.setOutAnimation(AnimationUtils.loadAnimation(ShowPhotoActivity.this,

                            android.R.anim.slide_out_right));

                    imageSwitcher1.setImageResource(R.drawable.girl2);

                   

                } 

                return true

            } 

            return false

        } 

    }; 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.