2012-05-07 23 views
5

アンドロイドでスライドショーとして画像を表示したい。その画像はjsonデータ形式でサーバーから取得されます。画像を表示する画像スライダでその画像をどのように渡すことができるか教えてください。 jsonのサーバーから来る画像の数、それは完全に動的で、画像のグループです...アンドロイドで画像スライドショー

答えて

8

あなたがする必要があるのは、jsonから来る画像の数を取ることです。すべての画像を取得すると、水平なページを使用してユーザに表示することができます。このlinkのような各スワイプの画像です。それ以外の場合は、2つのフレームを使用し、2つのアニメーションを設定し、スライダのように表示できます。このコードは役に立ちます。

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

回答を受け入れることで、stackoverflowの評判を向上させることができます。返信してアップしてください。 –

2

今後のJson Dataを解析し、画像のURLを取得する必要があります。 このデータを使用すると、ViewPagerを使用できます。そのアダプタでは、asyncTaskを実行して のViewPagerのアイテムレイアウトに画像を表示できます。

また、スライダのアニメーション(フェードイン、フェードアウトなど)を使用してViewFlipperを使用することもできます。 論理は同じでなければなりません

関連する問題