android中的图像幻灯片放映

时间:2012-05-07 09:31:34

标签: android json image

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

2 个答案:

答案 0 :(得分:8)

最初您需要做的是对来自json的图像进行计数。当您获得所有图像时,您可以使用horizo​​ndal页面向用户显示它。它有助于在每个滑动中更改图像,如此link。否则你可以使用两个框架,可以设置两个动画,并像滑块一样显示它。我认为这段代码可以帮助你。

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

答案 1 :(得分:2)

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

或者您可以将ViewFlipper与滑块一起使用动画(如淡入,淡出)。 逻辑应该是相同的