Android:在图像视图中显示图像数组

发布于 2024-11-26 22:39:43 字数 145 浏览 4 评论 0原文

我想从可绘制对象中一张一张地加载图像数组。在给定时间,当用户滑动时,ImageView 应该显示一张图像,它应该加载下一张图像。

我能达到这个目的吗??我不喜欢图库视图,我直接需要加载填充屏幕并滑动到数组末尾的单个图像。

预先感谢您的宝贵时间。

I want to load array of Images one 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‖放下 2024-12-03 22:39:43

查看 ImageSwitcher。它应该适合您的需求。

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

中性美 2024-12-03 22:39:43

我有一个不同的解决方案:

https://github.com/ysamlan/horizo​​ntalpager

这是一个 ViewGroup,您可以在其中添加子项,当向左或向右滑动时,您将全屏显示下一个或上一个子项。它还被编写为可以在您需要时实现垂直滚动。

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.

对岸观火 2024-12-03 22:39:43

您可以使用 ViewFilpperViewSwitcherImageSwitcher 以满足您的目的。所有这些类都扩展了 ViewAnimator,因此它们具有非常相似的行为和功能,并且仅在 ViewAnimator 的基础上添加了一些有用的功能。

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

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

口干舌燥 2024-12-03 22:39:43

经过几个小时的思考后,我想出了解决方案,因为没有一个答案对我有帮助。

  1. 加载 Imageview
  2. onclick 将使用 Animation 更改 imageview 图像。

Java代码

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++;

                }


        }

    }

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++;

                }


        }

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文