5

我想在 android 中将图像显示为幻灯片放映。这些图像将以 json 数据格式来自服务器。你能告诉我如何在将显示图像的图像滑块中传递这些图像吗?来自服务器的 json 图像数量,它是完全动态的,一组图像......

4

2 回答 2

8

最初,您需要做的是计算来自 json 的图像的数量。当您获得所有图像时,您可以使用水平页面向用户显示它。它有助于更​​改每次滑动中的图像,就像在这个链接中一样。否则您可以使用两个帧,可以设置两个动画并像滑块一样显示它。我认为这段代码会对您有所帮助。

if (imagesetflag == true) {
                Right_to_left_in = AnimationUtils.loadAnimation(this,
                        R.anim.right_to_left_in);
                Right_to_left_out = AnimationUtils.loadAnimation(this,
                        R.anim.right_to_left_out);
                left_to_Right_in = AnimationUtils.loadAnimation(this,
                        R.anim.left_to_right_in);
                Left_to_Right_out = AnimationUtils.loadAnimation(this,
                        R.anim.left_to_right_out);

                frame1.setImageBitmapReset(decryptedimage, 0, true);
                TVpagenum.setText("Page no:" + Currentpage + "/"
                        + countOfPages);
                frame1.bringToFront();
                frame1.setVisibility(View.VISIBLE);
                frame2.setVisibility(View.INVISIBLE);
                frame1.setAnimation(Right_to_left_in);
                frame2.setAnimation(Right_to_left_out);                                     
                imagesetflag = false;
            } else {
                Right_to_left_in = AnimationUtils.loadAnimation(this,
                        R.anim.right_to_left_in);
                Right_to_left_out = AnimationUtils.loadAnimation(this,
                        R.anim.right_to_left_out);
                left_to_Right_in = AnimationUtils.loadAnimation(this,
                        R.anim.left_to_right_in);
                Left_to_Right_out = AnimationUtils.loadAnimation(this,
                        R.anim.left_to_right_out);

                frame2.setImageBitmapReset(decryptedimage, 0, true);
                TVpagenum.setText("Page no:" + Currentpage + "/"
                        + countOfPages);
                frame2.bringToFront();
                frame2.setVisibility(View.VISIBLE);
                frame1.setVisibility(View.INVISIBLE);
                frame2.setAnimation(Right_to_left_in);
                frame1.setAnimation(Right_to_left_out);                 
                imagesetflag = true;
            }
于 2012-05-07T09:44:24.210 回答
2

您应该解析即将到来的 Json 数据并获取图像 url。有了这些数据,您可以使用 ViewPager,在其适配器中,您可以执行 asyncTask 以在 ViewPager 的项目布局中显示图像。

或者,您可以为滑块使用带有动画(如淡入、淡出)的 ViewFlipper。逻辑应该是一样的

于 2012-05-07T09:41:07.600 回答