如何以编程方式更改布局的可见性 [英] How to change visibility of layout programmatically

查看:90
本文介绍了如何以编程方式更改布局的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以更改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文档:

public void setVisibility(int visibility)

   因为: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 这很有道理.如果您有AWT/Swing的任何经验,您会从ContainerComponent之间的关系中认识到它. (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.)

这篇关于如何以编程方式更改布局的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆