我在画廊中居中图像时遇到问题。我希望它们填充画廊中可用的最大空间,但不希望它们在屏幕顶部被剪切。我想看看他们的顶部而不是底部。
我的问题是如何设置位置以便我可以在图库中看到图像的“顶部”?
images.setScaleType(ImageView.ScaleType.CENTER_CROP)
将图像设置为填充所有可用空间并保持其比例。问题是我的图像比宽度更高,因此它们的顶部不可见。
我有一个自定义画廊:CustomGallery,其布局是:
android:id="@+id/photos_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:spacing="0dp"
图库使用适配器:GalleryAdapter,它扩展了 BaseAdapter。它的 getView 方法如下:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView image = new ImageView(mcontext);
image.setLayoutParams(new Gallery.LayoutParams(
android.widget.Gallery.LayoutParams.FILL_PARENT,
android.widget.Gallery.LayoutParams.FILL_PARENT));
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageBitmap(getImgSource(position));
return image;
}