Put buttons at bottom of screen with LinearLayout?

前端 未结 9 1205
独厮守ぢ
独厮守ぢ 2020-11-28 18:25

I have the following code, how do I make it so that the 3 buttons are at the bottom?

    

        
9条回答
  •  鱼传尺愫
    2020-11-28 19:18

    You need to ensure four things:

    • Your outside LinearLayout has layout_height="match_parent"
    • Your inside LinearLayout has layout_weight="1" and layout_height="0dp"
    • Your TextView has layout_weight="0"
    • You've set the gravity properly on your inner LinearLayout: android:gravity="center|bottom"

    Notice that fill_parent does not mean "take up all available space". However, if you use layout_height="0dp" with layout_weight="1", then a view will take up all available space (Can't get proper layout with "fill_parent").

    Here is some code I quickly wrote up that uses two LinearLayouts in a similar fashion to your code.

    
    
    
        
    
        
    
            

    The result looks like similar to this:

    enter image description here

提交回复
热议问题