2012-07-02 1 views

답변

3

주요 아이디어는 getView 방법, 당신은 imagesArray 당신의 입술 폴더에있는 이미지를 보유하고있는 배열입니다

position = position % imagesArray.length; 
if (position < 0) 
    position = position + imagesArray.length; 

사용할 필요가 있다는 것입니다. 예를 들어 : 또한

public class CircularGallery extends Activity { 
/** Called when the activity is first created. */ 
private Integer[] imagesArray = { R.drawable.picture1, R.drawable.picture2, R.drawable.picture3, R.drawable.picture4, R.drawable.picture5, R.drawable.picture6 , R.drawable.picture7 }; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Gallery g = (Gallery) findViewById(R.id.gallery); 
    g.setAdapter(new ImageAdapter(this)); 

    g.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView parent, View v, int position, long id) { 
      if (position >= imagesArray.length) { 
       position = position % imagesArray.length; 
      } 
      Toast.makeText(CircularGallery.this, "" + position, Toast.LENGTH_SHORT).show(); 
     } 
    }); 

} 

public class ImageAdapter extends BaseAdapter { 
    int mGalleryItemBackground; 
    private Context mContext; 

    public ImageAdapter(Context c) { 
     mContext = c; 
     TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); 
     mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); 

     a.recycle(); 
    } 

    public int getCount() { 
     return Integer.MAX_VALUE; 
    } 

    public Object getItem(int position) { 
     if (position >= imagesArraylength) { 
      position = position % mImageIds.length; 
     } 
     return position; 
    } 

    public long getItemId(int position) { 
     if (position >= imagesArray.length) { 
      position = position % imagesArray.length; 
     } 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView i = new ImageView(mContext); 
     if (position >= imagesArray.length) { 
      position = position % imagesArray.length; 
     } 
     i.setImageResource(imagesArray[position]); 
     i.setLayoutParams(new Gallery.LayoutParams(80, 80)); 
     i.setScaleType(ImageView.ScaleType.FIT_XY); 
     i.setBackgroundResource(mGalleryItemBackground); 
     return i; 
    } 

    public int checkPosition(int position) { 
     if (position >= imagesArray.length) { 
      position = position % imagesArray.length; 
     } 
     return position; 
    } 
}} 

, 일부 개발자들은 이러한 기능을 수행하고 당신은 자신의 블로그

+0

왼쪽 면만 작업하고 싶습니다. 또한 오른쪽 면도 원합니다. –

+0

@ arsh.somal : gallery.setSelection (Integer.MAX_VALUE/2); – Anukool

0

내 첫 번째 추측은 어댑터 데이터를 변경하는 것입니다. 즉, "오른쪽 가장자리"에있는 것을 감지하면 첫 번째 이미지를 얻고 마지막에 추가 한 다음 두 번째 이미지를 찍으십시오.

2

에 소스를 찾을 수 있습니다 경우 오른쪽에 표시되는 이미지를 설정하려면 그냥을 설정하십시오.