2015-05-05 161 views
0

我想显示的imagefullscreen图像不全屏

public class PhotoPleinEcranActivity extends Activity { 

    private Bundle data; 
    private ImageView img; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 

     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.photo_plein_ecran); 

     img = (ImageView)findViewById(R.id.zoom); 

     BitmapFactory.Options bfOptions = new BitmapFactory.Options(); 
     bfOptions.inDither = true;      //Disable Dithering mode 
     bfOptions.inPurgeable = true;     //Tell to gc that whether it needs free memory, the Bitmap can be cleared 
     bfOptions.inInputShareable = true;    //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future 
     bfOptions.inTempStorage = new byte[32 * 1024]; 

     data = getIntent().getExtras(); 

     FileInputStream fs = null; 
     Bitmap bm; 
     try { 
      fs = new FileInputStream(new File(data.getString("path"))); 
      if(fs != null) { 
       bm = BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions); 
       img.setImageBitmap(bm); 
      } 
     } catch (IOException e) { 
     } finally { 
      if(fs != null) { 
       try { 
        fs.close(); 
       } catch (IOException e) { 
       } 
      } 
     } 

    } 

} 

布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginTop="0dip" 
    android:layout_marginBottom="0dip" 
    android:paddingTop="0dip" 
    android:paddingBottom="0dip" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/zoom" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="0dip" 
     android:layout_marginBottom="0dip" 
     android:paddingTop="0dip" 
     android:paddingBottom="0dip" 
    /> 

</LinearLayout> 

清单文件:

<activity 
    android:name="com.ambre.impots.PhotoPleinEcranActivity" 
    android:label="@string/galleryPhotos" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
</activity> 

在运行时有一灰字段在图像的底部(我用灰色包围了黄色):

enter image description here

那么如何使灰场消失?

+0

尝试添加'机器人:scaleType = “centerCrop”'你'imageView' – hrskrs

+0

尝试'机器人:scaleType = “fitXY”'和'机器人:adjustViewBounds = “真”' –

+0

可能重复[如何显示图像查看全屏在imageView点击?](http://stackoverflow.com/questions/24463691/how-to-show-imageview-full-screen-on-imageview-click) –

回答

3

这将解决您的问题。

在ImageView中添加以下行。

android:scaleType="fitXY" 
2

添加android:scaleType="fitXY"ImageView,fitXY,将填补宽度和高度分别以匹配目标

2

添加属性scaleType到fitXY这样

<ImageView 
     android:id="@+id/zoom" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="0dip" 
     android:layout_marginBottom="0dip" 
     android:paddingTop="0dip" 
     android:paddingBottom="0dip" 
     android:scaleType="fitXY" /> 
4

变化这样

<ImageView 
    android:id="@+id/zoom" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginBottom="0dip" 
    android:layout_marginTop="0dip" 
    android:adjustViewBounds="true" 
    android:paddingBottom="0dip" 
    android:paddingTop="0dip" 
    android:scaleType="fitXY" /> 
图像视图