GridLayout Column width

前端 未结 3 2071
伪装坚强ぢ
伪装坚强ぢ 2021-02-11 12:56

I have 2 columns in my GridLayout. What I want to do is make those columns take up half of the width of the screen each and then have its child contents fill their

3条回答
  •  一向
    一向 (楼主)
    2021-02-11 13:17

    adding views dynamically in a grid Layout of 2 columns that take 50% of the available space:

    GridLayout gridLayout = new GridLayout();
    
    View view; //it can be any view
    
    GridLayout.LayoutParams param = new GridLayout.LayoutParams();
    
    param.columnSpec = GridLayout.spec(GridLayout.UNDEFINED,GridLayout.FILL,1f);
    
    param.width = 0;
    
    view.setLayoutParams(param);
    
    gridLayout.add(view);
    

    in static way (in .xml file).

    
    
    
    
    
    
    
    
    
    
    
    

提交回复
热议问题