2012-07-12 51 views
0

我想放置一個填充屏幕寬度的圖像,具有實際圖像的高度(wrap_content),並位於佈局的最底部。Android。 ImageView將不能正確定位

我已經寫了下面的代碼,但在第二個ImageView(帶有drawable/user_board的那個)和屏幕的最底部之間有一個小空間。爲什麼是這樣?我已經嘗試將填充和邊距設置爲0dp,但它似乎並沒有做到這一點。有任何想法嗎?

下面是代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/LayoutBoard" 
       android:noHistory="true" 
       android:padding="0dp" > 
    <ImageView 
     android:src="@drawable/game_interface_background" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="matrix" /> 
    <ImageView 
     android:src="@drawable/user_board" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"   
     android:layout_alignParentBottom="true" 
     android:layout_margin="0dp" 
     android:padding="0dp" /> 
</RelativeLayout> 
+1

您是否使用hierarchyviewer查看實際填充和邊距值在運行時的樣子? – MattC 2012-07-12 14:29:05

+0

嗯。不,我以前沒有用過它,但我會將它谷歌它。謝謝。 – AndreiBogdan 2012-07-12 14:29:38

+1

這對於這些事情非常有用。祝你好運! – MattC 2012-07-12 14:30:15

回答

2

您的user_board圖片是否在底部有一些透明空間?或者,也許你可以嘗試在第二個填充字段ImageView中設置負值。

+0

Omg!就是這樣!我知道這很簡單,我只是錯過了。 :D我很喜歡這個網站:D – AndreiBogdan 2012-07-12 14:40:33

+0

很高興幫助你:) – 2012-07-12 14:41:06

1

使用android:scaleType="fitXY",幷包含在你的ImageView位圖將被重新調整,以適應整個ImageView。所以在這兩個圖像視圖中使用這個屬性可能會隱藏這個空白空間。但請記住,這不會保持圖像的寬高比。請參閱here以獲取有關android:scaleType屬性標記及其可能值的更多信息。

+0

不是。似乎沒有工作。地獄在這裏:))現在我生氣了!我一定錯過了一些東西,但我無法弄清楚什麼 – AndreiBogdan 2012-07-12 14:37:55

+1

@AndreiBogdan我只是嘗試了你的xml代碼,似乎工作(當然有不同的圖像)。也許正在發生什麼Dmytro Titov說。 – Angelo 2012-07-12 14:42:22