2013-03-16 72 views
0

我有一個LinearLayout(水平),我正在使用它來顯示3個ImageViews。當我第一次添加ImageView時,最後一張縮小了,因爲圖像太大而不適合3。這裏是我的設計師屏幕看起來像:我的圖像上的額外填充

after initially adding the three images

通知第三圖像收縮。

要解決此問題,我在每個ImageView上設置了以下屬性。

width: 0dp 
weight: 1 

這裏是我的圖片怎麼看設置這些屬性後:

after setting attributes

我運行到的是,即使畫面已經縮水問題仍然存在空間在頂部和底部如以下圖像中的藍色矩形所示:

padding

我的問題是,爲什麼這個額外填充那裏,我怎麼能擺脫它?

謝謝

更新 - 加入我的佈局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/RelativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_gravity="center" 
android:background="@color/app_background_color" 
android:contentDescription="@string/game_image_button" 
android:gravity="center" 
tools:context=".EasyActivity" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/ImageView02" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/game_image_button" 
     android:src="@drawable/ruler200x200" /> 

    <ImageView 
     android:id="@+id/ImageView01" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/game_image_button" 
     android:src="@drawable/ruler200x200" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:contentDescription="@string/game_image_button" 
     android:src="@drawable/ruler200x200" /> 
</LinearLayout> 

</RelativeLayout> 
+0

只是好奇,什麼尺寸是你原來的形象?我的意思是它是一個'x乘x'的方形圖像? – 2013-03-16 22:34:46

+0

它是200x200像素,它位於drawable_hdpi – 2013-03-16 22:36:58

+0

如果您發佈整個佈局的代碼將更容易理解 – lelloman 2013-03-16 22:45:09

回答

0

ImageViews支持不同ScaleTypes,默認爲FIT_CENTERhere是其他選項。 FIT_CENTER意味着它將從高度和寬度開始,等於您的圖像(在添加重量之前,您的圖像在第一個屏幕截圖中的樣子)。我相信發生的事情是,它會根據您的layout_weight重新調整圖像的寬度,並通過縮小圖像以適應新的寬度來保持圖像的寬高比。它離開高度成爲原始高度並以結果爲中心。

我認爲其他規模類型之一會做你想做的。也許CENTERCENTER_INSIDE

0

您可以使用下面的代碼

<Imageview..... 
android:adjustViewBounds="true" 
..../>