问题描述
有一种方法可以更改View的可见性,但是如何以编程方式更改XML中定义的布局的可见性?如何获取布局对象?
There is the way to change visibility of View, but how can I change programmatically visibility of layout defined in XML? How to get layout object?
<LinearLayout
android:id="@+id/contacts_type"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</LinearLayout>
推荐答案
看看View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE)
.
从 API文档:
因为:API级别1
Since: API Level 1
设置此视图的启用状态.
相关的XML属性:android:visibility
Set the enabled state of this view.
Related XML Attributes: android:visibility
参数:
visibility
可见,不可见或消失之一.
Parameters:
visibility
One of VISIBLE, INVISIBLE, or GONE.
请注意, LinearLayout
是 ViewGroup
反过来又是 View
.也就是说,您最好打个电话,例如myLinearLayout.setVisibility(View.VISIBLE)
.
这很有道理.如果您有AWT/Swing的任何经验,您会从Container
和Component
之间的关系中认识到它. (Container
是 Component
.)
This makes sense. If you have any experience with AWT/Swing, you'll recognize it from the relation between Container
and Component
. (A Container
is a Component
.)
这篇关于如何以编程方式更改布局的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!