[英]Include layout and exclude another one
In my project i have 3 xml files. 在我的项目中,我有3个xml文件。
My main layout 我的主要布局
and 2 layouts which i want to include in my main layout 和2个我想包含在主布局中的布局
*big_buttons.xml* >contains big size buttons *small_buttons.xml* >contains the same buttons as above (same id's aswell) but they are smaller * big_buttons.xml *>包含大尺寸按钮* small_buttons.xml *>包含与上述相同的按钮(也有相同的ID),但它们较小
By default i want the *big_buttons.xml* included, but id like to be able to "exclude" the *big_buttons.xml* and include the *small_buttons.xml* programmaticly after an onClickListener 默认情况下,我希望包括* big_buttons.xml *,但id希望能够在onClickListener之后以编程方式“排除” * big_buttons.xml *,并以编程方式包括* small_buttons.xml *
Is it possible to do something like this? 有可能做这样的事情吗?
By default you can use setContentView(R.layout.big_buttons);
默认情况下,您可以使用setContentView(R.layout.big_buttons);
, and then in your onClickListener you could do setContentView(R.layout.small_buttons);
,然后在您的onClickListener中可以执行setContentView(R.layout.small_buttons);
If it's specific buttons you want excluded rather than the entire XML, I think you need to combine the 2 XML files and by default give the "big buttons" the attribute android:visibility="visible"
and the "small buttons" android:visibility="gone"
. 如果您要排除特定的按钮,而不是整个XML,我认为您需要合并两个XML文件,并且默认情况下为“大按钮”赋予android:visibility="visible"
属性,为“小按钮”赋予android:visibility="gone"
。
Then programmatically you can do 然后以编程方式可以
Button bigButton = (Button) findViewById(R.id.big_button);
Button smallButton = (Button) findViewById(R.id.small_button);
bigButton.setVisibility("View.GONE");
smallButton.setVisibility("View.VISIBLE");
You'll want to use GONE rather than INVISIBLE because GONE excludes layout features like height and width, where INVISIBLE just doesn't display the button, but keeps space for it. 您将要使用GONE而不是INVISIBLE,因为GONE排除了诸如高度和宽度之类的布局功能,其中INVISIBLE只是不显示按钮,而是为其保留空间。
Check out View.setVisibility . 签出View.setVisibility 。 You can use this on a layout manager, so that you can make entire groups of controls visible or invisible from Java code. 您可以在布局管理器上使用它,以便可以使整个控件组在Java代码中可见或不可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.