我有一个屏幕,用户可以阅读文章(顶部有大照片).
它的一般结构是:
LinearLayout -> ScrollView -> LinearLayout -> ImageViews,TextViews...etc
我遇到问题的ImageView是顶部的大图像(在文章的标题下方,但在它的文字上方:
        <ImageView
            android:id="@+id/article_photo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/super_light_gray"
            android:scaleType="centerCrop"
            android:contentDescription="@string/articlePhoto"
            android:cropToPadding="true"
            android:layout_marginBottom="10dp"
            android:padding="1dp"/>
问题是,照片出现了,但是垂直裁剪很多,所以即使是垂直方向的照片也显得非常粗糙和宽阔.我认为"wrap_content"应该使它成为照片的全高......但我显然错了:)
如何让照片显示全宽(已经工作),还有全高?
我正在使用UniversalImageLoader来加载图像:
        if(lrgPhoto != null && !lrgPhoto.filepath.equals(""))
        {
            imageLoader.displayImage(
                "http://img.mysite.com/processes/resize_android.php?image=" + lrgPhoto.filepath + "&size=640&quality=90",
                imageView,
                imgDisplayOptions
                );
            imageView.setVisibility(View.VISIBLE); //show photo
        }
        else
        {
            imageView.setVisibility(View.GONE); //hide photo
            imageView.invalidate();
        }
编辑:
如果我将'scaleType'更改为'fitXY',那么图像会显示正确的尺寸而不会被裁剪,但是它不是全宽的.有没有办法让我可以同时拥有全宽和非裁剪?
看起来"裁剪"是因为它使用图像的原始高度作为高度,但它正在放大图像以适应全宽...
小智 29
将其添加到imageview xml:
android:adjustViewBounds="true"