子覆盖父级android layout_weight大小

时间:2014-08-30 13:38:40

标签: android android-layout android-layout-weight

我想成功完成以下布局

*<LinearLayout> 
  *<ListView with standard height = 50% of screen>
  *<TableLayout with standard height = 20% of screen>
  *<Fragment with standard height = 30% of screen> 
*</LinearLayout> 

这里的问题是Listview有时会有0个无限项。 当列表中没有项目时,Tablelayout和片段会上移到屏幕。

如何告诉Listview不根据listitem视图计算大小?

我已经尝试过以下方法,让Android工作室预览呈现正确的ui,但是当在设备上运行时,FrameLayout的高度为0,因为列表为空。

*<LinearLayout>
*  <FrameLayout and LinearLayout with weight>
*    <ListView>
*  </FrameLayout and /LinearLayout> 

*  <TableLayout with standard with weight>
*<Fragment with standard with weight> 

我真的很感激任何帮助。

1 个答案:

答案 0 :(得分:0)

the only solution I can think of is like that

*<LinearLayout>
  *<ListView with standard height = 50% of screen>
  *<View with standard height = 50% of screen visibily=gone>
  *<TableLayout with standard height = 20% of screen>
  *<Fragment with standard height = 30% of screen> 
*</LinearLayout> 

then when you find out that the ListView has 0 items change the visibility of the view.