android– 如何以编程方式更改布局的可见性

android– 如何以编程方式更改布局的可见性,第1张

概述有可能改变View的可见性,但是如何以编程方式更改XML中定义的布局的可见性?如何获得布局对象?<LinearLayoutandroid:id="@+id/contacts_type"android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="wrap_content&q

有可能改变VIEw的可见性,但是如何以编程方式更改XML中定义的布局的可见性?如何获得布局对象?

<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 docs:

public voID setVisibility(int visibility)

    Since: API Level 1

    Set the enabled state of this vIEw.
    Related XML Attributes: androID:visibility

Parameters:
visibility     One of VISIBLE, INVISIBLE, or GONE.

请注意,LinearLayoutViewGroup,而ViewGroup又是View.也就是说,您可能会调用mylinearLayout.setVisibility(VIEw.VISIBLE).

这是有道理的.如果您对AWT / Swing有任何经验,您可以从容器和组件之间的关系中识别它. (Container是一个组件.)

总结

以上是内存溢出为你收集整理的android – 如何以编程方式更改布局的可见性全部内容,希望文章能够帮你解决android – 如何以编程方式更改布局的可见性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1102030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存