我需要在GridView中显示的ImageView的三列,我想方的图像以避免这种影响https://www.dropbox.com/s/hjc55ijbf8cdkao/SC20130430-194230.png
这是我的XML代码:
图像裁剪以适合在GridView
<?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
或者他可以使用ImageView.ScaleType.CENTER_CROP的类似的形式,如果他这样希望得到最形象在那里是可以的,但cut-其余的不适合进入空间。 – 2013-04-30 18:24:54
他已经在使用CENTER_CROP。请检查张贴的代码。 – 2013-04-30 18:26:32
对。看起来,他正在使用正确的比例类型,因为他在第二眼之后连接了他想要的东西。我会重新阅读这篇文章。 – 2013-04-30 18:39:48