2016-09-30 28 views
2

我不完全明白的地方我的问题所在,所以我将提供尽可能多的信息,我可以,它的一些可能是无关找到了答案,但有些可能会有所帮助。位图不扩展到ImageView的

问题

我已经集成了一个摄像头在我的应用程序中,我使用的是surfaceView显示相机的预览,拍摄图像时,我采取原始图像字节和发送他们通过一个ObjectOutput流,我将显示该活动的图像。下面是该代码的一个片段:

out = new ObjectOutputStream(new FileOutputStream(new File(getActivity().getCacheDir(),"")+"cacheFile.srl")); 
out.writeObject(bytes); 

在我的字节读取和其他活动形象示:

bytes = (byte[]) in.readObject(); 
image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 
myHolder.setImageBitmap(image); 

下面是活动我的XML文件,该文件显示图像:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".fragments.Home"> 

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:id="@+id/ih" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentBottom="true"/> 

Here is the problem, I need to scale the image to fit the whole activity, yet there is white lines on either side

如果需要任何其他信息,请让我知道和虐待更新后

更新1

我改变了我的布局是:

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scaleType="centerCrop" 
    android:id="@+id/ih" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="100dp"/> 

但我仍然有白线或者侧

+0

阅读有关'ImageView'的'scaleType's – pskink

+0

请您可以共享图像的分辨率和设备? –

回答

0

设置android:scaleType="centerCrop"作为ImageView的属性如果你想图像适合其边界和其余的切割

您可以找到有关scaletypes这里更多的信息:https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

+0

我更新我的帖子,我想你说的是什么没有工作,看看更新的原帖 – BadCodersHub

+0

尝试设置机器人:adjustViewBounds =“真”,也许这有助于 – Katharina

+0

这个工作啊谢谢! – BadCodersHub