Android的布局显示/隐藏意见 [英] android layout hide/show views

查看:297
本文介绍了Android的布局显示/隐藏意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的线性垂直布局。我需要在我的应用程序切换按钮和TextView中。若要隐藏按钮,显示文本,然后更改等。如果我使用setVisibility(View.INVISIBLE),它从屏幕上消失的按钮,但它仍然坚持的位置。如何切换,而不将它们彻底删除这些元素?

 <天文台
        机器人:ID =@ + ID / chronometer1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =底部| CENTER_HORIZONTAL
        机器人:TEXTSIZE =30sp
        机器人:文字=天文台/>    <按钮
        机器人:ID =@ + ID / STOPBUTTON
        风格=机器人:ATTR / buttonStyleSmall
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/ stop_button/>
    <的TextView
        机器人:ID =@ + ID / wrongCounter
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =底部| CENTER_HORIZONTAL
        机器人:TEXTSIZE =30sp
        机器人:文字=/>


解决方案

使用 -

  button.setVisibility(View.GONE);

I have a linear vertical layout as below. I need in my application to switch the Button and the TextView. To hide button and show text then change etc. If I use setVisibility(View.INVISIBLE) for the button it disappears from the screen but it still hold the place. How can I switch those elements without remove them completely?

        <Chronometer
        android:id="@+id/chronometer1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:textSize="30sp"
        android:text="Chronometer" />

    <Button
        android:id="@+id/stopButton"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/stop_button" />


    <TextView
        android:id="@+id/wrongCounter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:textSize="30sp"
        android:text="" />

解决方案

use-

button.setVisibility(View.GONE);

这篇关于Android的布局显示/隐藏意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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