0

我在相對佈局中有兩個圖像瀏覽。一個人的行爲幾乎是另一個人的3倍。這兩個png都是60px x 60px,所以我不明白爲什麼要畫一個3倍的寬度。圖像沒有被拉伸,它在相對佈局中只佔用了3倍的寬度。在Android中具有相同xml屬性的兩個ImageView相對佈局

兩個imageviews:

<RelativeLayout 
    android:id="@+id/linerlayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="50dp" 
    android:layout_above="@+id/container_ide" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:background="@drawable/gradient" > 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_weight="1" 
     android:clickable="true" 
     android:onClick="that" 
     android:padding="6dp" 
     android:src="@drawable/icon_image" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_weight="1" 
     android:clickable="true" 
     android:onClick="this" 
     android:padding="6dp" 
     android:src="@drawable/image_two" /> 

</RelativeLayout> 

他們應該(在我的知識)的行爲如出一轍。正如你在下面的截圖中看到的,@drawable/image_two正在採取行動。三倍太寬的邊界框正在破壞我的佈局。有任何想法嗎?

enter image description here

回答

2

您的代碼工作正常,我有不同的圖像。

或許這與你的形象有關?

+0

感謝您花時間測試代碼,但是......我很困惑它爲什麼不能使用此映像。這是一個.png,我很困惑。 – EGHDK

+0

實際上,我仔細檢查圖像,看起來圓的大小更大,大概是寬度的三倍。但我認爲imageView縮小以適應它的父母? – EGHDK

+1

@EGHDK'ImageView'試圖適應圖像的原始大小,但是由於您已指定'RelativeLayout'的高度,因此Android只需在ImageView中最適合圖像的情況下添加額外的空間。如果將'RelativeLayout'更改爲'android:layout_hight =「wrap_content」' – francisOpt