我目前正在使用自定义 ArrayAdapter 作为列表。列表项跨越屏幕的整个宽度,因此在某些设备上非常宽。
我覆盖了ImageView
一些列表项,您可以滑动以将其关闭。的xmlImageView
如下:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:scaleType="matrix"
android:src="@drawable/myImage" />
视图放置正确,但为了使图像适合具有真正宽屏幕或横向模式的设备,图像必须非常宽。
问题是,我想缩放图像以垂直适合(即fitY
不存在作为 a scaleType
,然后将图像锚定到视图的左侧,并且对于不适合裁剪的所有内容。
我已经尝试了所有的scaleType
值,但没有一个是完全正确的。因此,我觉得我可能应该使用matrix
并定义我自己的图像翻译,所以我尝试了这个getView
:
//snipped out code before to initiate variables etc.
Drawable src = imageView.getDrawable();
//scale by the ratio of the heights.
int scaleFactor = imageView.getHeight() / src.getIntrinsicHeight();
Matrix imageMatrix = new Matrix();
//set the scale factor for the imageMatrix
imageMatrix.setScale(scaleFactor, scaleFactor);
//set the translation to be 0,0 (top left);
imageMatrix.setTranslate(0,0);
//assign the image matrix to the imageview.
imageView.setImageMatrix(imageMatrix);
但这根本没有任何影响(即使我让这些值真的很疯狂)。我想我将 imageMatrix 设置在错误的位置 - 是否有一个onDraw()
事件我可以为自定义ArrayAdapter
子类挂钩?
还是我要以完全错误的方式解决问题?