2013-03-09 44 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