2012-05-21 78 views
32

Làm thế nào để có được bố trí tương đối của tôi để hiển thị xem hình ảnh của tôi như thế này:nền Hình ảnh Android để lấp đầy màn hình

enter image description here

Thay vì điều này ?:

enter image description here

Tôi muốn tôi bố cục để hiển thị nhiều hình ảnh nhất có thể và cắt hình ảnh bên ngoài của hình ảnh, như khi bạn đặt hình nền trên màn hình nền thành "Điền" trong cửa sổ:

enter image description here

layout xml của tôi cho đến nay:

<?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> 

Trả lời

30

Thêm một loại quy mô ImageView của bạn. Có một số loại. Một trong những gì bạn cần là

android:scaleType="center" 

page Điều này sẽ giúp giải thích tất cả các loại khác nhau.

+0

chỉ là những gì tôi đang tìm kiếm, nhờ – kmb64

4

Đặt các thông số ImageView bố trí để match_parent và đặt loại quy mô với một loại quy mô thích hợp đáp ứng đầy đủ nhu cầu của bạn:

<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" 'tại là' scaleType = "centerCrop" –

Các vấn đề liên quan