twoByTwo1.setText("TOP"); twoByTwo1.setTextAppearance(this, android.R.style.TextAppearance_Large); gridLayout.addView(twoByTwo1, first); twoByOne1.setText("Staff Choices"); twoByOne1.setTextAppearance(this, android.R.style.TextAppearance_Large); gridLayout.addView(twoByOne1, second); twoByOne2.setText("Games"); twoByOne2.setTextAppearance(this, android.R.style.TextAppearance_Large); gridLayout.addView(twoByOne2, third); twoByOne3.setText("Editor's Choices"); twoByOne3.setTextAppearance(this, android.R.style.TextAppearance_Large_Inverse); gridLayout.addView(twoByOne3, fourth); twoByOne4.setText("Something Else"); twoByOne4.setTextAppearance(this, android.R.style.TextAppearance_Large); gridLayout.addView(twoByOne4, fifth); twoByTwo2.setText("BOTOM"); twoByTwo2.setTextAppearance(this, android.R.style.TextAppearance_Large_Inverse); gridLayout.addView(twoByTwo2, sixth);
Spec row1 = GridLayout.spec(0); Spec row2 = GridLayout.spec(1); Spec row3 = GridLayout.spec(2); Spec row4 = GridLayout.spec(3); Spec col0 = GridLayout.spec(0); Spec col1 = GridLayout.spec(1); Spec col2 = GridLayout.spec(2); GridLayout gridLayout = new GridLayout(this); GridLayout.LayoutParams first = new GridLayout.LayoutParams(row1, col0); /*Here you can set options for first cell which is in first row and first column.*/ first.width = screenWidth; first.height = quarterScreenWidth * 2; twoByTwo1.setLayoutParams(first); twoByTwo1.setGravity(Gravity.CENTER); twoByTwo1.setBackgroundColor(Color.RED); twoByTwo1.setText("TOP"); twoByTwo1.setTextAppearance(this, android.R.style.TextAppearance_Large); gridLayout.addView(twoByTwo1, first) //You can set all cells like above.
GridLayout gridLayout = new GridLayout(this); gridLayout.setColumnCount(colCount); gridLayout.setRowCount(rowCount); GridLayout.LayoutParams third = new GridLayout.LayoutParams(0, 0); textView1.setLayoutParams(third); gridLayout.addView(textView1, third); GridLayout.LayoutParams fourth = new GridLayout.LayoutParams(0, 1); cb.setLayoutParams(fourth); gridLayout.addView(cb, fourth); GridLayout.LayoutParams fifth = new GridLayout.LayoutParams(0, 2); textView2.setLayoutParams(fifth ); gridLayout.addView(textView2, fifth);
btn = new Button(this); btn.setText("Button " + i +"."+j); grd.addView(btn, gllop);
gridLayout.addView(contentLayout);
gl.addView(text[i]);