2012-07-20 3 views
2

갤러리와 ViewPager 위젯을 모두 사용했습니다. 웹 서비스 인 에서 이미지를 가져 오는 중이지만 ViewPager에는 배치 할 수 없지만 쉽게 갤러리에 배치 할 수 있습니다. 나는 내가이 작업을 수행 할 수있는 방법, 뷰 페이지 호출기와 같은 안드로이드 갤러리 스크롤

이 가능하다는 ViewPager 스크롤과 같은 안드로이드 갤러리 위젯 스크롤을 원하는 ViewPager http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/

이 튜토리얼을 사용했다.

+0

[갤러리 위젯] (http://developer.android.com/reference/android/widget/Gallery.html)은 이제 더 이상 사용되지 않습니다. 아마 ViewPager를 사용해야합니다. ViewPager를 사용하면서 질문을 편집하고 문제를 게시 할 수 있다면 해결 방법을 찾을 수 있습니다. – FoamyGuy

+0

@Tim 나는 내 질문을 편집하고 확인했다. 동적으로 뷰를 생성하고 추가 할 수 있으며 클릭 리스너가 필요하다. –

+0

ViewPager 만 사용하면 문제가 해결되고 호출기 뷰 내에서 지정해야한다. 실제로 레이아웃입니다) 표시하려는 항목 (특정보기에서) 클릭 이벤트를 처리합니다. – MobileEvangelist

답변

6

이미지 뷰를 동적으로 채우는 PagerAdapter의 instantiateItem() 메소드에 대한 기본적인 예입니다.

@Override 
public Object instantiateItem(final View pager, final int position) 
{ 
    //Note: if you do not have a local reference to the context make one and 
    //set it to the context that gets passed in to the constructor. 
    //Another option might be to use pager.getContext() which is how its 
    //done in the tutorial that you linked. 
    ImageView mImg = new ImageView(context); 

    /*Code to dynamically set your image goes here. 
    Exactly what it will be is going to depend on 
    how your images are stored. 
    In this example it would be if the images 
    are on the SD card and have filenames 
    with incrementing numbers like: (img0.png, img1.png, img2.png etc...)*/ 

    Bitmap mBitmap = BitmapFactory.decodeFile(
     Environment.getExternalStorageDirectory() + "/img" + position + ".png"); 
    mImg.setImageBitmap(mBitmap); 




    ((ViewPager) collection).addView(mImg, 0); 
    return mImg; 

} 
+0

흠,이게 저에게 효과가 있다면 월요일에 말해 줍니 다. –

+0

덕분에 완벽하게 작동했습니다. –

+0

완벽하게 작동하는 문제가 하나뿐입니다. 왜 그 효과가 보이지 않는지 알지 못합니다. 왼쪽, 일부 블로그를 읽고, 몇 가지 문제가 왼쪽 및 맨 위에 만 페이드 표시, 오른쪽 (getRightEdgeFading), 모든 제안에 대한 메서드를 재정의해야합니까 ??? –

관련 문제