gpt4 book ai didi

android - 图像裁剪以适合 GridView

转载 作者:行者123 更新时间:2023-11-30 03:38:00 24 4
gpt4 key购买 nike


我需要在 GridView 中显示三列 ImageView 并且我想对图像进行方形处理以避免这种效果 https://www.dropbox.com/s/hjc55ijbf8cdkao/SC20130430-194230.png

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>

<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth" >

</GridView>

和适配器:

public class PhotoListAdapter extends ArrayAdapter<Photo> {

Context context;

// Constructor
public PhotoListAdapter(Context context, ArrayList<Photo> mPhotoList) {
super(context, R.layout.item_album_detail, mPhotoList);
this.context = context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

// Inflating
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_album_detail, parent, false);

// Linking view by id
ImageView pic = (ImageView) convertView.findViewById(R.id.current_img);

// Get current item
Photo item = getItem(position);

// Set widget
pic.setScaleType(ImageView.ScaleType.CENTER_CROP);
ImageDownloader imgd = new ImageDownloader(pic);
imgd.execute(item.getPhoto_m());

return convertView;
}

}

在 item_album_detail.xml 中只有一个 ImageView

<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentDescription="@string/desc"
android:id="@+id/current_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />

我希望得到这个https://www.dropbox.com/s/i5gimy1lcwyavui/SC20130430-195710.png

最佳答案

更改比例类型将解决您的问题。但图像可能看起来有些拉伸(stretch)。

pic.setScaleType(ImageView.ScaleType.FIT_XY);

关于android - 图像裁剪以适合 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16306365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com