(android控件)ImageSwitcher介绍和使用说明


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

        } 

    }; 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM