Android重新发布问题
请帮帮我 我的xml布局是这样的Android重新发布问题,android,layout,Android,Layout,请帮帮我 我的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 weig
<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
正是我所需要的——四组均匀分布在屏幕上
但是,当我以[例如]第二个子布局可见性消失了
开始活动,并在运行时使其可见时,整个根/父布局看起来非常糟糕。子视图[来自子布局]彼此混乱,看起来它们的位置没有重新计算以考虑新的linearlayout
变得可见
requestLayout()
和forceLayout()
没有帮助
如何使根布局执行与活动刚开始时相同的操作?
<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>
........
........
........
........
毕竟我能让它工作。现在所有的更新都正确了,尽管我认为这不是真正的解决方案。我刚刚将重新计算布局可见性的代码移动到onWindowFocusChanged
回调,并在代码中手动设置android:weightSum
。
相信
onSizeChanged
回调也会有帮助。当代码或布局出现问题时,“伪代码”不是最好的主意。在这里发布您使用的确切布局。设置android:weightSum非常有趣,我会使用它。谢谢