I am trying to fit the image into gridview. But I don't understand from where my gridview is getting the height of the view.
The cell of the grid view is smaller than the image. I want to display the image full in a cell. But I don't want to hard code the size of the ImageView.
My codes
gridView in xml
<GridView
android:id="@+id/gridview_movie_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:numColumns="auto_fit"
android:columnWidth="185dp"
android:stretchMode="columnWidth"/>
My ImageView which I am inflating.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
And my getView method in my adapter class
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
mContext.LAYOUT_INFLATER_SERVICE);
ImageView imageView;
if (convertView == null) {
imageView = (ImageView) inflater.inflate(R.layout.grid_view_item, null);
} else {
imageView = (ImageView) convertView;
}
Picasso.with(mContext).setLoggingEnabled(false);
Picasso.with(mContext)
.load(imageResource[position])
.into(imageView);
return imageView;
}
This is what I get
And this is what is required
What worked for me was adding this line to my image view xml.
android:adjustViewBounds="true"
Now my output is just like what I wanted. Thanks for the help every one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With