2012-05-21 43 views
32

如何讓我的相對佈局來顯示這樣的我的形象的看法:Android的背景圖像,以填補屏幕

enter image description here

取而代之的是?:

enter image description here

我想我的佈局以儘可能多地顯示圖像並裁剪圖像的外部,例如當您將桌面背景圖像設置爲在窗口中「填充」時:

enter image description here

我的XML佈局至今:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     style="@style/SessionResumeBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/home_resumeSessionBar_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <Button 
      android:id="@+id/home_resumeSessionBar_buttonResume" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Resume" /> 
    </LinearLayout> 





</RelativeLayout> 

回答

30

添加一個規模型到您的ImageView。有幾種類型。你需要的是一個

android:scaleType="center" 

page將有助於解釋各種不同類型。

+0

正是我一直在尋找,謝謝 – kmb64

4

設置ImageView佈局參數match_parent並設置規模型到滿足您的需求的適度規模類型:

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:scaleType="centerCrop" 
    android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/> 
+1

'scale_type =「center_crop」'現在' scaleType = 「centerCrop」' –