2012-05-29 3 views
0

이미지와 함께 스크롤하는 배경을 가진 가로 이미지 갤러리를 만들려고합니다. 기본적으로 이것은 필름 롤에서 일련의 그림처럼 보입니다.Android : 갤러리의 스크롤 배경

이 문제를 해결하는 방법에 대한 아이디어가 있습니까? 아무도 이런 걸 시도하지 않았 니?

지금 당장 타일링 된 배경을 가진 두 LinearLayouts 사이에 갤러리보기를 끼워 넣었습니다. 이것은 내가 원하는 모습을 얻지 만 애니메이션은 사용하지 않습니다.

답변

0

나는 마침내 그것을 알아 냈다! 바라기를 이것은 누군가를 도울 수 있기를 바랍니다.

public ImageAdapter(Context context) { 
     galleryContext = context; 
     imageSizeInPixels = 300; //default value of 300x300 px 
     TypedArray styleAttr = galleryContext.obtainStyledAttributes(R.styleable.imageGallery); 
     galleryBackground = styleAttr.getResourceId(R.styleable.imageGallery_android_galleryItemBackground, 0); 
     styleAttr.recycle(); 
    } 

    private File[] getFiles() { 
     File file = new File(GlobalVars.picDir); 
     File imageList[] = file.listFiles(); 
     return imageList; 
    } 

    public int getCount() { 
     return imageList.length; 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     RelativeLayout container = new RelativeLayout(galleryContext); 

     ImageView imageView = null; 
     if (convertView != null) { //we can reuse the view! 
      imageView = (ImageView) convertView; 
     } else { 
      imageView = new ImageView(galleryContext); //boo we have to make a new view 
     } 

     //Get a scaled Bitmap so that it doesn't use up all our memory 

     Bitmap setBitmap = loadScaledBitmap(imageList[position].getAbsolutePath(), imageSizeInPixels); 

     //set up our ImageView inside the gallery to display our Bitmap... 

     imageView.setImageBitmap(setBitmap); 
     imageView.setLayoutParams(new Gallery.LayoutParams(imageSizeInPixels, imageSizeInPixels)); 
     imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
     imageView.setBackgroundColor(Color.BLACK); 

     RelativeLayout borderImg = new RelativeLayout(galleryContext); 
     borderImg.setPadding(10, 5,10, 5); 
     borderImg.setBackgroundColor(0xff000000); 
     borderImg.addView(imageView); 


     RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(imageSizeInPixels, imageSizeInPixels); 
     imageParams.addRule(RelativeLayout.CENTER_VERTICAL); 
     imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 


     container.setBackgroundResource(R.drawable.repeat_reel); 
     container.setLayoutParams(new Gallery.LayoutParams(imageSizeInPixels, imageSizeInPixels+40)); 

     container.addView(borderImg, imageParams); 

     return container; 
    }