Android GridView outside the margins
<p>I have included some images in the gridview, at the end of the scroll, seems to come out of the margins without any reason. (see the image )Can anyone tell me why? I post the XML file and the Image Adapter.</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" &gt;

&lt;GridView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/gridView"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:numColumns="4"
    android:layout_marginBottom="20dp"/&gt;
</code></pre>

<p></p>

<pre><code>public class ImageAdapter extends BaseAdapter {
    private Context context;

    public ImageAdapter(Context c) {
        context = c;
    }

    //---returns the number of images---
    public int getCount() {
        return imageName.length;
    }

    //---returns the ID of an item---
    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    //---returns an ImageView view---
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {
            imageView = new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(185, 185));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5, 5, 5, 5);
        } else {
            imageView = (ImageView) convertView;
        }
        imageView.setImageResource(imageName[position]);
        return imageView;
    }
}
</code></pre>

<p><a href="https://i.stack.imgur.com/TAiQv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TAiQv.png" alt="enter image description here"></a></p>