GridLayout (not GridView) how to stretch all children evenly

后端 未结 20 2118
独厮守ぢ
独厮守ぢ 2020-11-22 09:35

I want to have a 2x2 grid with a buttons inside. This is only ICS so I am trying to use the new GridLayout given.

Here\'s the XML of my layout:

 <         


        
20条回答
  •  臣服心动
    2020-11-22 10:14

    Here you are :

    Button button = new Button(this);
    // weight = 1f , gravity = GridLayout.FILL 
    GridLayout.LayoutParams param= new GridLayout.LayoutParams(GridLayout.spec(
                GridLayout.UNDEFINED,GridLayout.FILL,1f),
                GridLayout.spec(GridLayout.UNDEFINED,GridLayout.FILL,1f));
    // Layout_height = 0 ,Layout_weight = 0
    params.height =0;                                                                                                           
    params.width = 0;
    button.setLayoutParams(param);
    

提交回复
热议问题