2012-01-26 11 views
2

私は画像のリストを持っています。私はそのユーザーが左右にスライドして画像を見ることができるようにしたい。私はギャラリービューについて知っていますが、私はユーザーが画像をスライドさせるAndroid Galleryアプリケーションに組み込まれているようなものが欲しいです。Androidギャラリーのような画像のスライダー

答えて

4

をスライド
 public boolean onTouch(View view, MotionEvent event) 
{ 
    switch (event.getAction()) 
    { 
    case MotionEvent.ACTION_DOWN: 
     fromPosition = event.getX(); 
     break; 
    case MotionEvent.ACTION_UP: 
     float toPosition = event.getX(); 
     if (fromPosition > toPosition) 
     { 
      flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.go_next_in)); 
      flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.go_next_out)); 
      flipper.showNext(); 
     } 
     else if (fromPosition < toPosition) 
     { 
      flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.go_prev_in)); 
      flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.go_prev_out)); 
      flipper.showPrevious(); 
     } 
    default: 
     break; 
    } 
    return true; 
} 

....すべてのスライドはXMLで記述されている

 flipper = (ViewFlipper) findViewById(R.id.flipper); 

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    int layouts[] = new int[]{ R.layout.first, R.layout.second, R.layout.third, R.layout.fourth, 
      R.layout.fifth, R.layout.sixth, R.layout.seventh, R.layout.eighth, R.layout.nineth, R.layout.tenth, 
      R.layout.eleventh, R.layout.twelveth, R.layout.thirteen }; 
    for (int layout : layouts) 
     flipper.addView(inflater.inflate(layout, null)); 

...あなたのコード内でフリッパーを使用してみてください

関連する問題