Android 很好地缩放图像视图
其想法是要么显示一张照片,要么——如果没有定义——一个象征它的小图标 我已在布局中定义了以下ImageView:Android 很好地缩放图像视图,android,android-layout,android-imageview,Android,Android Layout,Android Imageview,其想法是要么显示一张照片,要么——如果没有定义——一个象征它的小图标 我已在布局中定义了以下ImageView: <ImageView android:id="@+id/imgPic" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds=
<ImageView
android:id="@+id/imgPic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@+string/strImgPic"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:saveEnabled="false"
android:src="@drawable/pic_icon" />
ImageDownloader()基本上只做异步检索图像的工作。然而,问题是如果没有图像(imgURL.Langthh()=0),则图标在布局中的一个空正方形的中间显示一个非常大的“边框”。p>
我希望图像缩小(或放大)到父视图的宽度,但图标要按原样显示(大约90度宽和高)
关于如何实现这一点有什么建议吗?查看图像视图的标签。如果您添加
android:scaleType="fitXY"
在布局的ImageView
定义中,图像将调整为ImageView
大小。大概是这样的:
<ImageView
android:id="@+id/imgPic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@+string/strImgPic"
android:paddingRight="10dip"
android:scaleType="fitXY"
android:paddingTop="10dip"
android:saveEnabled="false"
android:src="@drawable/pic_icon" />
但是,这将无法保持纵横比,因此图像可能会失真。如果您不希望这样,请检查android:scaleType
标记在提供的链接中可以接受的其他值
<ImageView
android:id="@+id/imgPic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@+string/strImgPic"
android:paddingRight="10dip"
android:scaleType="fitXY"
android:paddingTop="10dip"
android:saveEnabled="false"
android:src="@drawable/pic_icon" />