안녕하세요 저는 gallary 요소를 반복적으로 표시하고 싶습니다. 즉 앞으로 또는 뒤로 이동하면 갤러리 이미지의 끝은 필요 없습니다 .23 개의 elemets 배열을 사용하여 갤러리에 이미지를 다시 할당하면 반복해서 앞뒤로 움직이면됩니다.이 중 하나는 나에게 몇 가지 제안을 해주세요. 미리 감사드립니다.갤러리 요소를 반복하십시오
1
A
답변
6
이것은 거의 this question과 비슷합니다. getView()
메소드에서 조건을 작성하여 마지막 요소에 있는지 확인한 다음 getCount의 모듈러스를 사용하여 처음에 다시 시작해야합니다.
편집 이 다시 사용할 수있는 예가 될 수있다 : 코드 아래
public class TestGallery extends Activity {
private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
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 >= mImageIds.length) {
position = position % mImageIds.length;
}
Toast.makeText(TestGallery.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.default_gallery);
mGalleryItemBackground = a.getResourceId(R.styleable.default_gallery_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return Integer.MAX_VALUE;
}
public Object getItem(int position) {
if (position >= mImageIds.length) {
position = position % mImageIds.length;
}
return position;
}
public long getItemId(int position) {
if (position >= mImageIds.length) {
position = position % mImageIds.length;
}
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
if (position >= mImageIds.length) {
position = position % mImageIds.length;
}
i.setImageResource(mImageIds[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 >= mImageIds.length) {
position = position % mImageIds.length;
}
return position;
}
}
}
1
가 원형 GalleryView을 위해 아주 좋은 예입니다.
관련 문제
- 1. 각 x 요소를 반복하십시오.
- 2. WPF - 목록의 요소를 반복하십시오.
- 3. 갤러리 요소를 원으로 표시
- 4. 모든 YUI 위젯을 반복하십시오.
- 5. ASP.Net - 현재 페이지의 모든 HTML 구성 요소를 반복하십시오.
- 6. 갤러리
- 7. linq imultipleresults - 결과를 반복하십시오.
- 8. 디렉토리의 특정 파일을 반복하십시오.
- 9. 내 메뉴를 반복하십시오.
- 10. Jquery, 간단한 애니메이션으로 반복하십시오.
- 11. 알림에 tickerText를 반복하십시오.
- 12. 특정 요일에 UILocalNotification을 반복하십시오.
- 13. AVQueuePlayer의 AVPlayerItem을 반복하십시오.
- 14. 반투명 NSImage를 반복하십시오.
- 15. 설정된 간격으로 소리를 반복하십시오.
- 16. 레일 - 메서드 이름을 반복하십시오.
- 17. Lucene : 모든 항목을 반복하십시오.
- 18. 마우스 위치에 따라 요소를 움직이는 jQuery 갤러리 스크립트를 찾고 있습니다 (예 : 슬라이딩 갤러리 용)
- 19. 아이폰 UI 컨트롤을위한 갤러리
- 20. GUI 인터페이스를 반복하십시오. 약간 수정하거나 새로 만드시겠습니까?
- 21. 파이썬으로 : x : 00 간격으로 반복하십시오.
- 22. 파이썬 : 클래스 메소드를 사용하여 반복하십시오.
- 23. 데이터 프레임의 열 이름을 반복하십시오.
- 24. jquery가있는 모든 id ""를 반복하십시오.
- 25. PHP에서 SimpleXml 객체를 통해 반복하십시오.
- 26. 데이터 바인딩 된리스트 박스를 반복하십시오
- 27. 배치 스크립트에서 파일 이름을 반복하십시오.
- 28. Mathematica에서 함수를 n 번 반복하십시오.
- 29. jQuery에서 window resize 함수를 반복하십시오.
- 30. ResourceDictionary에 의해로드 된 StaticResource를 반복하십시오.
미안 나의 나쁜, 난 당신에 복사하기 전에 뭔가를 잊어 버렸습니다. "checkPosition (position); 앞에"position = "을 추가하십시오." in getView – Sephy
나는 위의 예제를 수정하여 모든 것을 작동시켰다. – Sephy
getItem 메소드에서 실수 한 것처럼 보입니다. – Zammbi