2012-05-21 5 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" ' –

Смежные вопросы