2014-01-14 18 views
0

我使用XML繪製:圖片無法在Android中正確縮放。

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/splashscreen" 
    android:tileMode="disabled" android:gravity="top" > 
</bitmap> 

這是我在佈局中的ImageView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/splash_image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     /> 

</RelativeLayout> 

但無論我做什麼,它不適合屏幕,僅出現在中心作爲一個小圖像。我哪裏錯了?

回答

0

嘗試使用FILL_PARENT 每個設備具有不同的屏幕尺寸,所以你需要做出不同的開機畫面的每個大小和分辨率我想這個問題是您正在使用的小尺寸(高度寬度)和顯示的圖像是大 如此需要縮放圖像以適應顯示大小,這可能會像素化圖像

+0

您應該使用'MATCH_PARENT','FILL_PARENT'已棄用。從[ViewGroup.LayoutParams](http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html)'FILL_PARENT(在API級別8和更高的重命名MATCH_PARENT),這意味着該視圖希望成爲大如其父(減去填充)' – quinnjn

+0

單詞「過時」不是在上面的鏈接提到。閱讀兩遍!它只是說它已被重命名(重命名!=棄用)。 –

+0

對不起,我很抱歉,我猜MATCH_PARENT被改名了。但我認爲其他部分是正確的,這是我爲我的解決方案所做的。爲不同的屏幕尺寸製作不同的圖像。 –

1

也許不是最好的解決方案,因爲不同的設備有不同的分辨率,但「WRAP_CONTENT」將顯示在其原始分辨率的圖像。

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <ImageView 
      android:id="@+id/splash_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/splashscreen" 
     /> 
    </RelativeLayout>