2013-02-01 106 views
2

我的应用程序的一个屏幕显示了一个包含6列的列表视图,第六个是包含用户创建的图片或草图的imageView。下面是对于ListView行的代码:其中所显示的图像是由照相机拍摄的垂直方向的画面:除了一个案例Android中的Listview在某些行的顶部和底部添加额外空间

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:paddingTop="2dp" 
    android:paddingBottom="2dp" > 

    <TextView android:id="@+id/surveyColumn1" 
     android:textSize="13sp" 
     android:layout_width="0dip" 
     android:layout_weight="0.105" 
     android:layout_height="wrap_content"/> 

    <TextView android:id="@+id/surveyColumn2" 
     android:textSize="13sp" 
     android:layout_width="0dip" 
     android:layout_weight="0.137" 
     android:layout_height="wrap_content"/> 

    <TextView android:id="@+id/surveyColumn3" 
     android:textSize="12sp" 
     android:layout_width="0dip" 
     android:layout_weight="0.25" 
     android:layout_height="wrap_content"/> 

    <TextView android:id="@+id/surveyColumn4" 
     android:textSize="13sp" 
     android:layout_width="0dip" 
     android:layout_weight="0.153" 
     android:layout_height="wrap_content"/> 

    <TextView android:id="@+id/surveyColumn5" 
     android:textSize="13sp" 
     android:layout_width="0dip" 
     android:layout_weight="0.153" 
     android:layout_height="wrap_content"/> 

    <ImageView android:id="@+id/surveyColumn6" 
     android:layout_width="0dip" 
     android:layout_weight="0.202" 
     android:layout_height="wrap_content" 
     android:paddingTop="0dp" 
     android:paddingBottom="0dp" 
     android:scaleType="centerInside" 
     android:layout_gravity="center" 
     android:contentDescription="@string/pictureHeader"/> 

</LinearLayout> 

这种设置的伟大工程。在这种情况下,listview会在行内部的图像上方和下方抛出一堆空白区域。在这个活动中,我使用的是一个custumViewBinder来使用代码将图像显示为位图:http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

我发现摆脱空间的唯一方法是将静态高度设置为imageView ,我宁愿不这样做,因为有些行不会有图像。任何能够弄清楚发生的事情都是我的英雄。

编辑:这是我打电话作为位图,以显示图像的类:

public class customBitmap { 

    public customBitmap(String pathName, int width, int height, ImageView view) { 
     final BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     BitmapFactory.decodeFile(pathName, options); 

     options.inSampleSize = calculateInSampleSize(options, width, height); 

     options.inJustDecodeBounds = false; 
     Bitmap bitmap = BitmapFactory.decodeFile(pathName, options); 

     //Check if bitmap was created; if so, display it in the imageView 
     if(bitmap == null) 
      Log.w("UI Thread", "Null bitmap at moto.sitesurvey.customBitmap:35"); 
     else 
      view.setImageBitmap(bitmap); 
    } 

    public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight){ 
     final int height = options.outHeight; 
     final int width = options.outWidth; 
     int inSampleSize = 1; 

     if(height > reqHeight || width > reqWidth) { 
      if(width > height) 
       inSampleSize = Math.round((float)height/(float)reqHeight); 
      else 
       inSampleSize = Math.round((float)width/(float)reqWidth); 
     } 

     return inSampleSize; 
    } 

} 

在我传递的200和150值的宽度和高度的活性。我的问题似乎是,几个月前我最初编写此代码时,我只设计它为面向横向的图片工作,现在它也需要为纵向工作。

回答

2

每stoney80的建议,在我post于r/androiddev,我增加了行

android:adjustViewBounds="true" 

到imageVew,这得到它做的正是我所期待的。

0

您是否在将图像放入视图之前调整图像大小?如果是这样,请检查并查看图像处理的最佳尺寸,并尝试将从垂直方向摄像头拍摄的位图调整为此大小。

如果这不帮助你,我可以看看你的imageview和位图代码?

+0

我正在调整它们的大小(请参阅新附加的代码),我想我发现200和150对于宽度和高度都很好,至少对于风景图片来说。我将如何测试垂直相机镜头? – VTDoubleE

相关问题