java - ImageViews inside GridView take up insane amount of space -


i trying fit in imageviews inside gridview. have written custom xml imageviews, custom java class extending arrayadapter gridview.

following activity initializes gridview

private gridview gridview; private customgridviewimage customgridviewimage;  @override protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_checkout2);          init();         handleclick();          gridview = (gridview) findviewbyid(r.id.gridview);         gridview.setadapter(customgridviewimage); 

following custom adapter

package in.juspay.ec.sdk.activities;  import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.imageview;  import in.juspay.ec.sdk.*;  /**  * created stpl on 21/7/16.  */ public class customgridviewimage extends arrayadapter<integer>{      private context context;     private integer[] imagearray;      public customgridviewimage(context context, int resource, integer[] imagearray)     {         super(context, resource, imagearray);         this.context = context;         this.imagearray = imagearray;     }      @override     public view getdropdownview(int position, view convertview, viewgroup parent) {         return getcustomview(position, convertview, parent);     }      @override     public view getview(int position, view convertview, viewgroup parent) {         return getcustomview(position, convertview, parent);     }      public view getcustomview(int position, view convertview, viewgroup parent)     {         layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);         view cell = inflater.inflate(r.layout.custom_gridview_image, parent,false);           imageview imageview = (imageview) cell.findviewbyid(r.id.custom_gridview_imageview);         imageview.setimageresource(imagearray[position]);          return cell;     } } 

following in custom xml imageview

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="50dp"     android:layout_height="50dp"     android:padding="5dp"     android:gravity="center_horizontal">      <imageview         android:layout_width="match_parent"         android:layout_height="match_parent"         android:id="@+id/custom_gridview_imageview"         android:scaletype="fitcenter" />  </linearlayout> 

and lastly, xml gridlayout

    <gridview        android:background="#e8bc9e"        android:id="@+id/gridview"        android:layout_margintop="30dp"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:numcolumns="2"        android:columnwidth="50dp"        android:horizontalspacing="5dp"        android:stretchmode="spacingwidthuniform">    </gridview> 

i'm trying this

this

but end getting this

enter image description here

as can see, each grid cell takes insane amount of space after imageview. going wrong?

thank time!!

because assign 50dp x 50dp imageview's container (linearlayout) in custom layout. , tell gridview make 2 columns. images small , rest of area filled background color. can delete linearlayout section in custom layout , put image view width: match_parent, height: match_parent. or change linearlayout's width & height "match_parent".


Comments