2010-01-10 62 views
1

我擁有一個圖庫,其中包含一組在運行時下載的圖像。圖庫項目寬度vs圖庫寬度

我跟着這裏的例子:使用但 http://www.anddev.org/a_androidwidgetgallery_-_example-t332.html

代替

i.setImageResource(this.myImageIds[position]); 

我用

i.setImageBitmap(bitmaps.get(position)); 

這並不填滿屏幕的整個寬度,僅作爲就像這裏指定的寬度一樣:

i.setLayoutParams(new Gallery.LayoutParams(150, 150)); 

當我增加這個數字時,項目會隨着它而縮放,而不是在每個例子中顯示更多的圖像。我甚至在將圖像添加到集合之前嘗試縮放圖像。不知道我錯過了什麼,或者其他可能的例子。任何幫助將是偉大的,謝謝。

+0

什麼是目標 - 畫廊填滿屏幕或填滿屏幕的項目? – 2010-01-10 05:56:12

+0

我想讓畫廊填充屏幕的寬度,並且一次只顯示一幅圖像。 – 2010-01-12 03:15:40

+0

如何填充寬度並在每次顯示多個圖像? – 2011-03-28 18:40:10

回答

-1

在您的佈局xml文件一定要設置的android:layout_width =「FILL_PARENT」,類似這樣的

<Gallery 
      android:id="@+id/gallery" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="2dip" 
         android:layout_gravity="center_horizontal|bottom" 
         android:padding="1dip" 
         android:background="#AA000000" 
      /> 
1

看來,你可以設定爲圖像的真實尺寸佈局的寬度。或者通過某種邏輯來計算比例因子。例如,當圖像遠離圖庫中心時,可以減小圖像的寬度。我們可以使用ImageView(this.myContext)來創建一個新的ImageView(this.myContext)。

 i.setImageResource(this.myImageIds[position]); 
     /* Image should be scaled as width/height are set. */ 
     i.setScaleType(ImageView.ScaleType.FIT_XY); 
     /* Set the Width/Height of the ImageView. */ 
     int selectedPosition = ((Gallery) parent).getSelectedItemPosition(); 

     float scale = getScale(position - selected); 

      int width = Math.round(IMAGE_WIDTH * scale); 

      int height = Math.round(IMAGE_HEIGHT * scale); 

      i.setLayoutParams(new Gallery.LayoutParams(width, height)); 

     return i; 
    }