Issue
I am trying to create a project where I used a GridView to show images. But the problem is images can have various sizes. Some of them are big, some of them are small. So I want to fit the images in GridView perfectly. But whatever I try nothing makes it better. The following photo can clear more-
I want the pictures to be square sized and center-cropped but they are vertically stretched for some reason.
The relevant code snippets are below-
ImageView code
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:scaleType="centerCrop"
android:id="@+id/gridImage"/>
GridView code
<GridView
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:scrollbars="vertical"
android:horizontalSpacing="5dp"
android:verticalSpacing="3dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/line" />
GridAdapter code
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if(inflater==null)
inflater = (LayoutInflater) cx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(view == null)
view = inflater.inflate(R.layout.grid_item, null);
ImageView imageView = view.findViewById(R.id.gridImage);
Pictures p = pictures.get(i);
Glide.with(cx).load(p.getImageID()).centerCrop().placeholder(R.drawable.avatar).into(imageView);
return view;
}
I tried all the scaleTypes of ImageView but none of them made the images square, center-cropped and perfectly fitted inside the GridView. Am I missing something here?
Solution
android:adjustViewBounds="true" or android:scaleType="fitXY" for VIew please refer this enter link description here
Answered By - rv_5143

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.