简体   繁体   English

如何在Android中的单个活动中具有两个布局xml文件

[英]How to have two layout xml files in a single activity in android

我正在用android开发应用程序。我想要的是,我的活动应该代表两个xml布局文件。概念就像,->活动开始时它应该显示一个布局(屏幕)->当我单击按钮时存在第一个布局,它应该在屏幕底部显示第二个布局,并保持第一个布局可见。

Have both the layout in a single XML. 将两个布局都放在一个XML中。 Keep the visibility of the the second layout to secondLayoutObject.setVisibility(View.GONE) initially and then on the click of the button change its visibility to secondLayoutObject.setVisibility(View.Visible) . 首先将第二个布局的可见性保持为secondLayoutObject.setVisibility(View.GONE) ,然后单击该按钮,将其可见性更改为secondLayoutObject.setVisibility(View.Visible)

On method to call two xml files in on activity is by using layoutmanager and assign the screen ratio for both xml files. 在on活动中调用两个xml文件的on方法是使用layoutmanager并为两个xml文件分配屏幕比例。 Use relative layout in both xml. 在两个xml中使用相对布局。 Small code snippet is 小代码段是

RelativeLayout layleft = (RelativeLayout)inf.inflate(R.layout.firstxml,null);
        RelativeLayout layright = (RelativeLayout)inf.inflate(R.layout.secondxml,null);

for detail info Layout Reuse help 有关详细信息, 布局重用帮助

For this you have to use the concept of visibility. 为此,您必须使用可见性的概念。 Initially set visibility of second layout as GONE and when you press button set Its visibility True. 最初将第二个布局的可见性设置为GONE,然后按按钮将其可见性设置为True。

you can try use the bellow example: 您可以尝试使用以下示例:

https://github.com/AdilSoomro/Iphone-Tab-in-Android https://github.com/AdilSoomro/Iphone-Tab-in-Android

this source code to change layout like button click to load another layout! 此源代码可以更改布局,例如单击按钮以加载另一个布局!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM