GridLayout (not GridView) how to stretch all children evenly

后端 未结 20 2203
独厮守ぢ
独厮守ぢ 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:29

    This is a fairly old question, but obviously of interest to a lot of people. For a simple layout of 4 buttons like this, it seems that a TableLayout is the easiest way to accomplish the desired result.

    Here's some example code showing the first 2 rows of a table with 6 columns spanning the width of its parent. The LinearLayout and ImageView in each cell are used to allow for the "turning on and off" of an image within the cell while having the color of the cell persist.

    
    
        
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
        
    
        
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
    
            
    
                
            
        
    
    

提交回复
热议问题