2
我已将main_layout.xml
作为根布局,无所谓是RelativeLayout
或LinearLayout
。并且该根布局具有不同的布局。 Basicly它看起来是这样的:如何动态更改与另一个布局的布局
<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
)相同的身高和体重。我只想切换它们。
也许我的想法是不正确的,我可能需要不同的方法。我对你的建议很感兴趣。任何帮助都会很棒。
使用viewswitcher – njzk2
有趣的是,也许把它们全部放在一个布局中,然后在您的Java中动态设置它们的可见性。 –
我会看看'ViewSwitcher'谢谢你njzk2。 @userIsAMonkey将所有功能集成在一个布局中是一种解决方案,但因此很难设计布局。无论如何,如果没有其他答案,我会尝试,谢谢。 – Martin