2012-05-29 44 views
0

我試圖用一個包含平鋪背景的佈局包圍我的ImageView的頂部和底部。頂部似乎工作,但底部佈局不顯示。任何想法爲什麼?這是我的getView():Android:底部佈局不顯示在圖庫中

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

      RelativeLayout topReel = new RelativeLayout(galleryContext); 
      RelativeLayout bottomReel = new RelativeLayout(galleryContext); 

      topReel.setBackgroundResource(R.drawable.film_top); 
      bottomReel.setBackgroundResource(R.drawable.film_bottom); 

      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.setBackgroundResource(galleryBackground); 

      RelativeLayout.LayoutParams topParams = new RelativeLayout.LayoutParams(imageSizeInPixels, 20); 
      topParams.addRule(RelativeLayout.ABOVE, imageView.getId()); 
      topParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 


      RelativeLayout.LayoutParams bottomParams = new RelativeLayout.LayoutParams(imageSizeInPixels, 20); 
      bottomParams.addRule(RelativeLayout.BELOW, imageView.getId()); 
      bottomParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 

      RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(imageSizeInPixels, imageSizeInPixels); 
      imageParams.addRule(RelativeLayout.BELOW, topReel.getId()); 
      imageParams.addRule(RelativeLayout.ABOVE, bottomReel.getId()); 
      imageParams.addRule(RelativeLayout.CENTER_VERTICAL); 
      imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 


      container.addView(topReel, topParams); 
      container.addView(bottomReel, bottomParams); 
      container.addView(imageView, imageParams); 

      return container; 
     } 

回答

0

這解決了問題,希望有人可以用這個:

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(), ((int)(imageSizeInPixels * .75))); 

      //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; 
     }