2013-04-13 20 views
1

我爲我的Android應用程序的UI使用了一些.png圖像。我已將圖像保存在「res/drawable」目錄中。我在一些教程中看到,當屏幕分辨率大於mdpi時,Android會自動擴展圖像。但是,當我在大屏幕設備上運行我的應用程序時,圖像顯示爲原始大小,而不是放大。其餘的空間是空的(黑色)。我在這裏做錯了什麼?下面是我的佈局的XML,如果它有幫助:圖像沒有被放大(Android)

<?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:orientation="vertical" 
    android:theme="@android:style/Theme.Black.NoTitleBar" 
     > 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/imageView1" 
     android:clickable="false" 
     android:contentDescription="@string/p" 

     android:src="@drawable/volbar" /> 



    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="false" 
     android:contentDescription="@string/p" 

     android:src="@drawable/head" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/imageView1" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="33dp" 
     android:layout_marginRight="19dp" 
     android:text="@string/press_to_update" /> 

    <ImageView 
     android:id="@+id/imageView9" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/imageView2" 
     android:clickable="false" 
     android:contentDescription="@string/p" 

     android:src="@drawable/frag11" 
     /> 
    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView9" 
     android:layout_alignParentLeft="true" 
     android:clickable="false" 
     android:contentDescription="@string/p" 

     android:src="@drawable/base" /> 

</RelativeLayout> 
+0

您是否已根據圖像的分辨率將圖像上傳到res文件夾? – iRushnikov

+0

是的,正確的分辨率已經上傳到drawable-mdpi和hdpi目錄中。 –

回答

1

我猜你想要你的圖像擴大到填充空間。如果是這樣的話,你需要爲你的ImageView指定scaledType

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scaleType="cropInside" /> 

試驗不同的值從ImageView.ScaleType得到你想要的效果。

僅供參考,當您在res/drawable中放置圖像時,它會根據設備密度進行縮放。例如,如果您的PNG是200x150,那麼它將在具有1.5密度的設備上縮放到300x225。這種縮放發生獨立於scaleType

+0

好的,我會測試一下。順便說一句,我認爲當屏幕比較大時,將填充尺寸增大到填充屏幕,並且在屏幕較小時降低屏幕填充。抱歉的帽子。 –