简体   繁体   English

隐藏和显示android布局-如何标记活动布局?

[英]Hiding and showing android layouts - How do you mark active layout?

I'm just writing my first android app and in one layout xml file I have four buttons that will display a different layout when pressed. 我只是编写我的第一个android应用程序,并且在一个布局xml文件中,我有四个按钮,当按下它们时它们将显示不同的布局。 Instead of creating four seperate screens, I've just put the four layouts in the same layout as the buttons with android:visibility="GONE", and then when a button is pressed, I set it's corresponding layout to being visible. 我没有创建四个单独的屏幕,而是将四个布局与带有android:visibility =“ GONE”的按钮放置在相同的布局中,然后在按下按钮时,将其对应的布局设置为可见。

My question is, is there a best practice or suggested method for keeping track of the active layout so that when a button is pressed you can set the active layout back to visibility="GONE" before making the new one visible. 我的问题是,是否有最佳实践或建议的方法来跟踪活动布局,以便在按下按钮时可以在使新布局可见之前将活动布局设置回可视性=“ GONE”。 I thought I could just set a string value with the ID of the active layout, but then findViewById wont take the string to get a hold of the layout. 我以为我可以用活动布局的ID设置一个字符串值,但是findViewById不会采用该字符串来获取布局的保留权。 Any help or suggestions would be great. 任何帮助或建议将是巨大的。 Thanks! 谢谢!

Why do you use a string to save the ID of the layout? 为什么使用字符串保存布局的ID? Can you not just use an int since the ID's are such? 由于ID如此,您不能只使用int吗? Or set the visibility of the layouts from the onClickListener you attached to each button? 还是通过附加到每个按钮的onClickListener设置布局的可见性?

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

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