2012-07-27 18 views
1

我有一個圖像,有分辨率,以適應我的測試設備上的整個屏幕。當使用其他屏幕尺寸進行測試時,圖像只適合寬度或高度,並留出空白空間,因爲它總是按比例縮放。如果比例變化,我怎麼能設置圖像以適應全屏?例如,如果我的設備屏幕是3/4,則圖像將在3/4顯示上正確縮放,而與其分辨率無關。但是,16/9不適合全屏。安卓適合圖像填充整個佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:background="@color/blueish" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:src="@drawable/splashandroid" 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     </ImageView> 


</LinearLayout> 

還試圖WRAP_CONTENT圖像佈局寬度

+0

您是否嘗試過在ImageView中嘗試android:scaleType =「fitXY」 – rajpara 2012-07-27 11:20:28

+0

嘗試添加android:scaleType =「fitXY」 然而,這將不會保持圖像的縱橫比 – 2012-07-27 11:20:35

+0

設置圖像視圖的寬度和高度作爲填充父項。 – AkashG 2012-07-27 11:25:26

回答

2

在你加入這個ImageView的,android:scaleType="fitXY"或者你可以在你使用此活動意味着imgview.setScaleType(ScaleType.FIT_XY);

你可以用這個試試,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:background="@color/blueish" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:src="@drawable/splashandroid" 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="fitXY"/> 

</LinearLayout>