Set Columnspan And Columnweight Programmatically
I have been trying to add views to a gridLayout, wich I have done, but they're not adjusting to the columns as they should, I had tried inflate the views with the same atribute tha
Solution 1:
So, Trying a lot, and spending a lot of time finnally work with this:
GridLayout.LayoutParamsdoubleLayoutParams=newGridLayout.LayoutParams();
doubleLayoutParams.rowSpec = GridLayout.spec(i,1);
// GridLayout.spec(rowNumber,rowSpan);
doubleLayoutParams.columnSpec = GridLayout.spec(0, 2f);
// GridLayout.spec(columnNumber,columnSpan);TextViewnewName=newTextView(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);
Solution 2:
Try something like this
For android:layout_columnWeight
((GridLayout.LayoutParams) this.getLayoutParams()).columnSpec =
GridLayout.spec(GridLayout.UNDEFINED, 1f);
Checkout Set rowSpan or colSpan on Stack answers.
Post a Comment for "Set Columnspan And Columnweight Programmatically"