2013-03-09 52 views
1

我將圖像視圖設置爲全屏,但不起作用:左側和右側之間有一些空間。如何將imageview設置爲全屏?imageview未設置全屏

這是我的XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <ImageView android:id="@+id/imageView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
    </ImageView> 
</LinearLayout> 

回答

4

使用android:scaleType="fitXY"在你的XML:

<ImageView android:id="@+id/imageView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
/> 
+0

也可以使用'match_parent',而不是'fill_parent'。 'fill_parent'被認爲已被棄用。 – nabroyan 2013-03-09 07:54:26

0

請嘗試以下選項

android:scaleType="CENTER_CROP" 

縮放一個圖像均勻(維持圖像的縱橫比),以便兩個尺寸(寬度和高度)將等於或大於視圖的相應尺寸(減去填充)。

android:scaleType="CENTER_INSIDE" 

縮放圖像均勻(保持圖像的縱橫比),以使圖像的兩個尺寸(寬度和高度)會比圖(減去填充)的對應尺寸等於或更少。

android:scaleType="fitXY" 

X和Y獨立縮放,以便src完全匹配dst。

如果你不關心的比例

ImageView imageView=new ImageView(context); 
imageView.setAdjustViewBounds(false); 
+0

in xml我很確定你想爲android:scaleType使用「centerInside」/「centerCrop」,否則你會得到一個錯誤 – ColossalChris 2015-03-24 23:04:43