android - Set ColumnSpan and ColumnWeight programmatically -


i have been trying add views gridlayout, wich have done, they're not adjusting columns should, had tried inflate views same atribute showing in xml had no success.

now, trying create views programatically isn't working, how can achive want?

relevant code:

this gridlayout

<android.support.v7.widget.gridlayout             android:id="@+id/grd_team_a"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="12dp"             android:horizontalspacing="1dp"             app:columncount="5"             app:orientation="horizontal">              <textview                 android:id="@+id/txtplayersnameti"                 android:text="jugadores"                 android:textsize="14sp"                 android:paddingtop="5dp"                 android:paddingbottom="5dp"                 app:layout_columnweight="2"                 app:layout_columnspan="2"                 android:textstyle="bold"/>             <textview                 android:text="goles"                 android:gravity="center_horizontal"                 android:paddingright="5dp"                 android:textsize="14sp"                 android:paddingtop="5dp"                 android:paddingbottom="5dp"                 app:layout_columnweight="1"                 app:layout_columnspan="1"                 android:textstyle="bold"/>             <imageview                 android:src="@drawable/ic_yellow_card_match"                 android:gravity="center_horizontal"                 android:textsize="14sp"                 android:paddingtop="5dp"                 android:paddingbottom="5dp"                 app:layout_columnweight="1"                 app:layout_columnspan="1"                 android:textstyle="bold"/>             <imageview                 android:src="@drawable/ic_red_card_match"                 android:gravity="center_horizontal"                 android:paddingtop="5dp"                 android:paddingbottom="5dp"                 app:layout_columnweight="1"                 app:layout_columnspan="1"                 android:textstyle="bold"/>         </android.support.v7.widget.gridlayout> 

this how looks in xml preview:

enter image description here

and how should data:

enter image description here

but, after adding code:

int = 2;             loading=false;             gridlayout.spec col2 = gridlayout.spec(2);             gridlayout.spec col3 = gridlayout.spec(3);             gridlayout.spec col4 = gridlayout.spec(4);             gridlayout.spec colspan2 = gridlayout.spec(0, 1);             grdteamaplayers.setcolumncount(5);             grdteamaplayers.setrowcount(teamaplayers.size()+2);              for(tournamentplayer newplayer: teamaplayers)             {                 gridlayout.spec row = gridlayout.spec(i);                 gridlayout.layoutparams first = new gridlayout.layoutparams(row, colspan2);                 gridlayout.layoutparams goals = new gridlayout.layoutparams(row, col2);                 gridlayout.layoutparams yellow = new gridlayout.layoutparams(row, col3);                 gridlayout.layoutparams red = new gridlayout.layoutparams(row, col4);                  textview newname = new textview(mycontext);                 newname.settext(newplayer.getname() + " " + newplayer.getlastname());                 newname.settextcolor(contextcompat.getcolor(mycontext, r.color.black_50));                 newname.settextsize(14);                 newname.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent));                 grdteamaplayers.addview(newname, first);                   textview newgoals = new textview(mycontext);                 newgoals.settext(newplayer.getgoals() + "");                 newname.settextsize(14);                 newgoals.settextcolor(contextcompat.getcolor(mycontext, r.color.black_50));                 newgoals.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent));                  textview newyellow = new textview(mycontext);                 newyellow.settext(newplayer.getyellowcards() + "");                 newname.settextsize(14);                 newyellow.settextcolor(contextcompat.getcolor(mycontext, r.color.black_50));                 newyellow.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent));                  textview newred = new textview(mycontext);                 newred.settext(newplayer.getredcards()+"");                 newname.settextsize(14);                 newred.settextcolor(contextcompat.getcolor(mycontext, r.color.black_50));                 newred.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.match_parent));                  grdteamaplayers.addview(newgoals, goals);                 grdteamaplayers.addview(newyellow, yellow);                 grdteamaplayers.addview(newred, red);                 i=i+1;             } 

what this:

enter image description here

edit:

yes, other titles dissapering , big white space showing.

so, trying lot, , spending lot of time finnally work this:

  gridlayout.layoutparams doublelayoutparams = new gridlayout.layoutparams();                     doublelayoutparams.rowspec = gridlayout.spec(i,1);                     //  gridlayout.spec(rownumber,rowspan);                     doublelayoutparams.columnspec = gridlayout.spec(0, 2f);                     //  gridlayout.spec(columnnumber,columnspan);   textview newname =  new textview(mycontext);                     newname.settext(newplayer.getname().trim() + " " + newplayer.getlastname().trim());                     newname.settextcolor(contextcompat.getcolor(mycontext, r.color.black_50));                     newname.settextsize(12);                     newname.setellipsize(textutils.truncateat.end);                     newname.setsingleline();                     newname.setwidth(0);                     grdteamaplayers.addview(newname, doublelayoutparams); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -