2013-04-18 46 views
0

我想使用背景圖片,但我不知道必須爲不同大小的android設置大小,有幾個規範是您可以告訴我您需要使用像素大小。我的應用程序在主佈局用於背景的尺寸是多少?

+0

背景圖像是否像可以重複的瓷磚? – tbruyelle

回答

3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:background="@drawable/your_selected_background_image" 
> 

android:layout_width="fill_parent"android:layout_height="fill_parent"屬性將填補你的應用程序與你在任何設備上完全選擇的圖像背景。

+0

謝謝,我會試試 – diez

+0

不用客氣@diez。讓我知道這是你想要的。在我看來這將解決你的問題。 –

1

使用NinePatch圖像。

NinePatch是一個PNG圖像,您可以在該圖像中定義Android在視圖內的內容超出正常圖像範圍時可伸縮的區域。您通常將這種類型的圖像指定爲至少有一個尺寸設置爲「wrap_content」的視圖的背景,並且當視圖增長以適應內容時,Nine-Patch圖像也會縮放以匹配視圖的尺寸

<Button 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:background="@drawable/myninepatch" /> 

http://developer.android.com/guide/topics/resources/drawable-resource.html#NinePatch

0

據Android開發者文檔FILL_PARENT在API級別8或更高更名爲match_parent,這是推薦使用match_parent代替FILL_PARENT的。 math_parent/fill_parent可以使視圖的大小伸展到其父級的大小,所以如果在背景佈局中使用android:layout_width =「math_parent」和android:layout_height =「match_parent」。您的背景圖片會自動拉伸至您的屏幕尺寸(準確地說,取決於其父母的尺寸)。 wrap_content使視圖的大小足夠大以包含其有效性。因此,使用wrap_content時,視圖的大小和背景將根據視圖的內容展開。