我已将 main_layout.xml
作为根布局,无论它是 RelativeLayout
还是 LinearLayout
。该根布局有自己不同的布局。基本上它看起来像这样:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/default_background" >
<RelativeLayout
android:id="@+id/panel_bar">
<!-- -->
</RelativeLayout>
<RelativeLayout
android:id="@+id/other_bar">
</RelativeLayout>
<RelativeLayout
android:id="@+id/main_bar">
<Button id="@+id/change_button" />
</RelativeLayout>
</RelativeLayout>
当我点击 change_button
时,我想将 panel_bar
更改为其他布局,比如说 another_layout
。顺便说一下,another_layout 是不同文件中的现有布局。它们(panel_bar
和 another_layout
)具有相同的高度和重量。我只是想切换它们。
也许我的想法不正确,我可能需要不同的方法。我真的很想知道你的建议。任何帮助都会很棒。
最佳答案
最简单的方法是将两个布局都放入根布局中,并将其中一个的visible
设置为gone
,然后根据需要切换可见性。
关于android - 如何动态更改布局与另一个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12722203/