如何更改布局的知名度programaticly [英] How to change visibility of layout programaticly

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

问题描述

还有就是要改变视图的可见性的方式,但我怎么可以改变布局的XML定义programaticly的知名度?如何获取布局对象?

 <的LinearLayout
    机器人:ID =@ + ID / contacts_type
    机器人:方向=横向
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:能见度=水涨船高>
< / LinearLayout中>
 

解决方案

看一看 View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE)

API文档

  

公共无效setVisibility(INT可见性)

     

    自:API级别1

     

     设置这一观点的启用状态
      相关XML属性:安卓的知名度

     

参数:
      能见度    一个可见,不可见或消失。

请注意,<一个href="http://developer.android.com/reference/android/widget/LinearLayout.html"><$c$c>LinearLayout 的ViewGroup 而这又是一个 查看 。也就是说,你很可能调用,例如, myLinearLayout.setVisibility(View.VISIBLE)

这是有道理的。如果您有AWT / Swing的任何经验,你会从容器组件之间的关系认识它。 (A 容器组件

There is the way to change visibility of View, but how can I change programaticly 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>

解决方案

Have a look at View.setVisibility(View.GONE / View.VISIBLE / View.INVISIBLE).

From the 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.

Note that LinearLayout is a ViewGroup which in turn is a View. That is, you may very well call, for instance, myLinearLayout.setVisibility(View.VISIBLE).

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.)

这篇关于如何更改布局的知名度programaticly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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