2012-05-29 2 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; 
    } 
Смежные вопросы