1

I'm trying to add 9 button to my activity i would like to add button like these:

      <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_columnSpan="1"
            android:layout_rowSpan="1"
            android:text="@string/button1"
            android:layout_margin="5dp"/>

currently I'm using this

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Context context = this;
        GridLayout gridBoutons = findViewById(R.id.layout_gridBoutons);
        for(int i = 0; i != 9;i++){
            Bouton bouton = new Bouton(context);
            bouton.setText("");
            GridLayout.LayoutParams param = new GridLayout.LayoutParams();
            param.height = GridLayout.LayoutParams.WRAP_CONTENT;
            param.width = GridLayout.LayoutParams.WRAP_CONTENT;
            bouton.setLayoutParams(param);
            gridBoutons.addView(bouton);
        }
    }

I do not know how to have the column weight row weight column span and the row span

1 Answers1

1

You can use the following approach with API 21 and later mention in: Set rowSpan or colSpan of a child of a GridLayout programmatically?

https://developer.android.com/reference/android/widget/GridLayout.Spec

Spec spec(int start, int size, float weight)

param.rowSpec = GridLayout.spec(0, 1, (float)1.0);    
param.columnSpec = GridLayout.spec(0, 1, (float)1.0);