RelativeLayout is taking fullscreen for wrap_content

前端 未结 6 922
闹比i
闹比i 2020-11-27 14:58

Why does FOOBARZ get layed out all the way at the bottom when no elements are layout_height=\"fill_parent\" in other words, all elements are wrap_content for he

6条回答
  •  悲&欢浪女
    2020-11-27 15:53

    I'm not sure why the clean and obvious way of accomplishing this hasn't been posted yet. This performant solution works for any View MyView with a known height.

    Wrap your RelativeLayout with height wrap_content in a FrameLayout:

    
    
    
         
    
         
    
    

    Just note that the view at the bottom of the FrameLayout will be on top of your RelativeLayout content, so you'll need to add padding to the bottom of that layout to accomodate it. If you want that view to be variable height, you can either Subclass FrameLayout to add padding in code based on the measured view height, or just change the FrameLayout to vertical LinearLayout if you're not worried about the performance, i.e. it's not a listview item, or the views are relatively lightweight.

提交回复
热议问题