2012-11-26 51 views
0

帮我请Android的重新布局问题

我的XML布局是这样的

<LinearLayout width=fill height=wrap orient=horizontal> 
    <LinearLayout width=0 height=wrap weight=1>...</> 
    <LinearLayout width=0 height=wrap weight=1>...</> 
    <LinearLayout width=0 height=wrap weight=1>...</> 
    <LinearLayout width=wrap height=wrap weight=0>...</> 
</LinearLayout> 

该充气main.xml不正是我需要的 - 在屏幕上均匀分布的四组。

但是当我以[例如]第二个子布局可见性GONE开始活动并在运行时将其设置为VISIBLE时,整个根/父布局看起来非常糟糕。子视图[从子图层]混乱,看起来像他们的立场没有重新计算,以考虑到新的linearlayout成为可见。

requestLayout()forceLayout()没有帮助。

如何让根布局与刚刚启动时的功能相同?

+0

当你的代码或布局有问题时,那么“伪代码”不是一个好主意。在此发布您正在使用的确切布局。 –

回答

0
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="4"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

</LinearLayout> 
+0

设置android:weightSum真的很有趣,我会用它。谢谢)) – mjollneer

+0

你的欢迎:) –

0

毕竟我得到它的作品。现在所有更新都正确,但我想这不是真正的解决方案。我只是将代码重新计算布局可见性,然后手动将代码移动到onWindowFocusChanged回调并在代码中设置android:weightSum。 相信onSizeChanged回调也可能有所帮助。