2011-07-29 15 views
1

画像の配列をdrawableから1つずつ読み込みたい。ある時点で、ImageViewはユーザーがスライドすると1つのイメージを表示し、次のイメージをロードします。Android:画像ビューで画像の配列を表示

これを達成できますか?私はギャラリービューが嫌いです、私は直接、単一の画像を読み込む必要があります。データは画面を満たし、Arrayの終わりまでスライドします。

お時間をいただきありがとうございます。

答えて

0

何時間も考えていたのですが、答えのどれも私を助けなかったので、私は解決策を思いつきました。

  1. ImageViewの
  2. はonclickのアニメーションと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++; 

       } 


     } 

    } 
3

ImageSwitcherに見てみましょう。それはあなたのニーズに合っているはずです。

2

私は別の解決策があります。それはあなたが左または右にスワイプすると、あなたはフルスクリーンで次または前の子が表示されます、子を追加することができますのViewGroupだ

https://github.com/ysamlan/horizontalpager

を。また、必要な場合に備えて垂直スクロールを実装することもできます。

+0

それはアンドロイドのホームスクリーンのような役割を果たし、それが位置し、すべてのものだし、それは、スナップ... – Androider

関連する問題