2011-03-09 91 views
0

我花了3個小時試圖讓這個工作沒有成功,所以這裏有人可以幫助。如何讓ImageView縮放圖像並對齊右上角?

我有一個是經由充氣加載從XML文件中的FrameLayout和在它我有以下佈局:

<LinearLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
     <ImageView 
     android:id="@+id/element_image" 
      android:layout_width="wrap_content" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:layout_marginBottom="10dip" 
      android:layout_marginLeft="10dip" 
      android:scaleType="fitStart" 
      android:background="#888888" >  
     </ImageView> 
     <Button android:id="@+id/element_button" 
      style="@style/Button" 
      android:layout_gravity="right" 
      android:text="@string/element_button_label" 
     /> 
    </LinearLayout> 

我有從中我想在此的ImageView以顯示BLOB加載的圖像。在GalleryAdaptor予加載這樣的圖像:

ImageView image = (ImageView) v.findViewById(R.id.element_image); 
    byte [] bitmapData = cursor.getBlob(4); 
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);    
    image.setImageBitmap(bitmap); 

當我使用機器人:scaleType =「fitStart」在圖像上方的佈局不進行縮放到的ImageView的高度或寬度,但大約是三分之一它的寬度(我可以從我給出的灰色背景中看到)並居中。

如果我使用android:scaleType =「fitXY」,圖像高度縮放,但寬度不是。圖像再次居中。

有人可以給我一些指點:

  1. 如何獲得的圖像縮放高度和寬度明智
  2. 如何對齊圖像右上方

回答

1

回答我的問題這裏 - 但看起來像這只是源圖像分辨率的問題。當使用fitStart或fitEnd時,Android(至少2.2)似乎不想縮放這些圖像 - 但是,當使用fitXY時,它會縮放它們。