Android: how to make a view grow to fill available space?

前端 未结 4 1793
清酒与你
清酒与你 2021-01-30 19:27

This seems straightforward, but I can\'t figure out how to do it. I have a horizontal layout with an EditText and two ImageButtons. I want the ImageButtons to be of a fixed si

4条回答
  •  日久生厌
    2021-01-30 19:54

    Okay:

    
    
            
            
            
            
            
            
    
    

    The key points of the layout are:

    • The items with fixed sized are placed first in the layout, this way when Android comes to calculating the height of the height of things with fill_parent later in the file it only takes into account the remaining space, not all of the space it could possibly occupy if nothing else was there
    • The EditText has a height of fill_parent (match_parent in 2.2+) so that it takes up the rest of the available space

    Sorry didn't read your question will enough. The above code provides the answer if you want to do it in a vertical fashion. For a horizontal layout the code posted by @Sunil should work.

提交回复
热议问题