开发者

Android: Show array of Images in Image View

I want to load array of Images o开发者_如何学Cne by one from drawable. At a given time the ImageView should display one image when user slides, it should load the next Image.

Can I acheive this?? I don't like gallery view, I directly need to load the single image dat fills the screen and slides through till the end of Array.

Thanks in advance for your time.


Take a look onto ImageSwitcher. It should fit your needs.


I have a different solution:

https://github.com/ysamlan/horizontalpager

It's a ViewGroup where you can add children, when swiping left or right, you will show the next or previous child in fullscreen. It's also written so that it's possible to implement vertical scrolling in case you need this.


You can use ViewFilpper or ViewSwitcher or ImageSwitcher for your purposes. All these classes extend ViewAnimator, so they have very similar behavior and functionality, and only add a few useful function on top of what ViewAnimator has.

Demo: http://www.youtube.com/watch?v=mGwG8-chUEM


After thinking for hours I came up with solution as none of the answers helped me.

  1. Load the Imageview
  2. onclick will change the imageview image with an Animation .

Java Code

public class ImagePreviewActivity extends Activity implements OnClickListener {

        public int currentimageindex=0;
        private int[] IMAGE_IDS ={R.drawable.splash1, R.drawable.splash2, R.drawable.image_preview, R.drawable.report_incident_exclamation_mark};


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.media_preview);
            ImageView imageview = (ImageView)findViewById(R.id.ImageViewPreview);
            imageview.setImageResource(R.drawable.splash1); 
            currentimageindex++;
            imageview.setOnClickListener(this);


        }


        @Override
        public void onClick(View v) {
            Animation inFromRight = new TranslateAnimation(
                    Animation.RELATIVE_TO_PARENT, +1.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f,
                    Animation.RELATIVE_TO_PARENT, 0.0f);
                inFromRight.setDuration(500);
                    ImageView imageview = (ImageView)findViewById(R.id.ImageViewPreview);
                    imageview.startAnimation(inFromRight);

                if ((IMAGE_IDS.length)> currentimageindex){

                    imageview.setImageResource(IMAGE_IDS[currentimageindex]);

                    currentimageindex++;

                }


        }

    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜