I own a project that has a multi-cell GridView and I need the cells that make up Gridview to fill every useful area of the SmartPhone screen. With the following XML code it did not work:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e4c5c5">
<GridView
android:id="@+id/gridView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:numColumns="7" />
</LinearLayout>
</LinearLayout>
importandroid.content.Context;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.BaseAdapter;importandroid.widget.TextView;importjava.util.List;publicclassCelulasAdapterextendsBaseAdapter{privateContextcontext;privateList<DiasMesApoio>arrayListDiasMes;privateintwidth;privateintheight;//Construtor:publicCelulasAdapter(Contextcontext,List<DiasMesApoio>arrayListDiasMes,intwidth,intheight){this.context=context;this.arrayListDiasMes=arrayListDiasMes;this.width=width;this.height=height;}@OverridepublicintgetCount(){returnarrayListDiasMes.size();}@OverridepublicObjectgetItem(intposition){returnarrayListDiasMes.get(position);}@OverridepubliclonggetItemId(intposition){returnposition;}@OverridepublicViewgetView(intposition,ViewconvertView,ViewGroupparent){ViewviewLayout;ViewHolderviewholder;if(convertView==null){LayoutInflaterinflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);viewLayout=inflater.inflate(R.layout.layout_celulas_gridview,null);viewholder=newViewHolder();viewholder.textView1=(TextView)viewLayout.findViewById(R.id.textView1);viewLayout.setTag(viewholder);convertView=viewLayout;}else{viewholder=(ViewHolder)convertView.getTag();viewLayout=convertView;}viewLayout.setMinimumHeight(GridViewActivity.height/6);DiasMesApoiodiasMesApoio=arrayListDiasMes.get(position);viewholder.textView1.setText(String.valueOf(diasMesApoio.getDia()));returnviewLayout;}privateclassViewHolder{TextViewtextView1;}}