显示-点击一次button隐藏RelativeLayout。

问题描述

点击一次button隐藏RelativeLayout。

XML是这样的。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.app.bangwoyi.MainActivity" >

        <Button
            android:id="@+id/dingdan1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:text="订单1" />

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="left"
            android:visibility="visible">

            <EditText
                android:id="@+id/timu"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="半喂入卧式割台联合收割机怎么翻译?"
                android:textSize="14dp" />

            <TextView
                android:id="@+id/daan1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/timu"
                android:layout_gravity="left"
                android:layout_marginTop="10dp"
                android:text="答案1: Seml-feeding"
                android:textSize="15dp" />

            <TextView
                android:id="@+id/daan2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/daan1"
                android:layout_marginTop="25dp"
                android:text="答案2: "
                android:textSize="15dp" />

            <TextView
                android:id="@+id/daan"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/daan2"
                android:layout_marginTop="30dp"
                android:text=".....: "
                android:textSize="15dp" />

            <TextView
                android:id="@+id/daan_n"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/daan"
                android:layout_marginTop="30dp"
                android:text="答案5:Horizontal cut "
                android:textSize="15dp" />

            <Button
                android:id="@+id/bt1"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBaseline="@+id/daan1"
                android:layout_alignBottom="@+id/daan1"
                android:layout_alignRight="@+id/timu"
                android:layout_marginRight="30dp"
                android:background="@drawable/dianzan" />

            <Button
                android:id="@+id/bt"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBaseline="@+id/daan2"
                android:layout_alignBottom="@+id/daan2"
                android:layout_alignRight="@+id/daan1"
                android:layout_marginRight="50dp"
                android:background="@drawable/bofang" />

            <Button
                android:id="@+id/bt2"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBaseline="@+id/daan2"
                android:layout_alignBottom="@+id/daan2"
                android:layout_alignLeft="@+id/bt1"
                android:layout_marginRight="20dp"
                android:background="@drawable/dianzan" />

            <Button
                android:id="@+id/bt3"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBaseline="@+id/daan"
                android:layout_alignBottom="@+id/daan"
                android:layout_alignLeft="@+id/bt2"
                android:background="@drawable/dianzan" />

            <Button
                android:id="@+id/bt4"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignLeft="@+id/bt3"
                android:layout_alignTop="@+id/daan_n"
                android:background="@drawable/buzan" />

            <TextView
                android:id="@+id/number1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/bt1"
                android:layout_toRightOf="@+id/bt2" />

            <TextView
                android:id="@+id/number2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/bt2"
                android:layout_toRightOf="@id/bt2" />

            <TextView
                android:id="@+id/number3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/bt3"
                android:layout_toRightOf="@id/bt2" />

            <TextView
                android:id="@+id/number4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/bt4"
                android:layout_toRightOf="@id/bt2" />

            <Button
                android:id="@+id/jt"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBaseline="@+id/timu"
                android:layout_alignBottom="@+id/timu"
                android:layout_toRightOf="@+id/timu"
                android:background="@drawable/jiantou" />

            <Button
                android:id="@+id/more"
                android:layout_width="40dp"
                android:layout_height="20dp"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/bt4"
                android:layout_marginTop="20dp"
                android:background="@android:color/transparent"
                android:gravity="right"
                android:text="more "
                android:textSize="15dp" />
        </RelativeLayout>

        <Button
            android:id="@+id/dingdan2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/linearLayout1"
            android:layout_below="@+id/linearLayout1"
            android:gravity="left"
            android:text="订单2" />

        <Button
            android:id="@+id/dingdan3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/dingdan2"
            android:layout_below="@+id/dingdan2"
            android:gravity="left"
            android:text="订单3" />

        <Button
            android:id="@+id/dingdan4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:text="订单4" />
    </LinearLayout>

</ScrollView>

我想点击第一个button,把下面的RelativeLayout隐藏,再点击一次又显示。求指点

解决方案

每次判断你下layout的visibility,如果是gone就设置为visible,如果是visible就设置为gone

解决方案二:

在button的onClickListener事件里修改Relativelayout对象的可见性即可

解决方案三:

更简单的方法,定义一个局部变量,分别给RelativeLayout的不同状态赋给不同的值,然后通过值来给RelativeLayout相应给他显示或者不显示的值。

时间: 2024-09-13 02:42:11

显示-点击一次button隐藏RelativeLayout。的相关文章

js实现的点击div区域外隐藏div区域_javascript技巧

首先看下JS的事件模型,JS事件模型为向上冒泡,如onclick事件在某一DOM元素被触发后,事件将跟随节点向上传播,直到有click事件绑定在某一父节点上,如果没有将直至文档的根. 阻止冒泡:1.stopPropagation()对于非IE浏览器.2.cancelBubble属性为true,对于IE浏览器, 而Jquery已经有兼容浏览器的方法,event.stopImmediatePropagation(); <!DOCTYPE html> <html> <head>

ontouchevent-android架子鼓怎么实现同时点击多个button同时响应操作的方法?

问题描述 android架子鼓怎么实现同时点击多个button同时响应操作的方法? 本人很爱玩音乐 看到ios平台很多音乐的模拟软件 吉他的~贝斯的 鼓的~~但是android平台却相当不给力 这些软件都很渣~~排名靠前的架子鼓的软件 竟然只能支持单指操作!就比如一个节奏咚次大次吧 kit(地鼓)和snare(踩镲)必须同时响起来 如果只支持单指操作的话 不能同时点击两个以上的鼓 这样模拟架子鼓的效果就太差了!! . . . 出于严重不满android平台音乐类软件质量的差劲 我就想自己捣鼓一个

android-点击按钮的时候隐藏图片

问题描述 点击按钮的时候隐藏图片 我想实现的是点击按钮时,一张图片隐藏一张图片显示, 下面是我的代码: ib=(ImageButton)findViewById(R.id.imagebutton1); ib1.setImageResource(i); Toast.makeText(MainActivity.this,"Fail",1000).show(); Thread.sleep(10000); ib1.setImageResource(R.drawable.bck_image1);

Microsoft图标显示错误,攻击者可任意隐藏恶意PE文件

本文讲的是Microsoft图标显示错误,攻击者可任意隐藏恶意PE文件, Windows中的图标显示错误允许攻击者使用特殊图标伪装PE文件,从本地设备自动"借用"其他常用图标,从而诱惑用户点击它们.这个漏洞目前已经根植在Windows的图像处理代码中了,根据我的分析,至少从Windows 7开始,该漏洞就已经出现,并且仍然存在于Windows 10的最新版本中. 我已经将该错误于2017年6月向微软正式报告了,而且本文对漏洞的分析也经过了微软的许可. 漏洞的发现 我在研究最近一批恶意P

jquery实现点击展开列表同时隐藏其他列表_jquery

本文实例讲述了jquery实现点击展开列表同时隐藏其他列表.分享给大家供大家参考.具体如下: 这里使用jquery实现展开.隐藏特效,点击列表标题后该项内容展开,其它项收缩起来,也就是不显示了.个人喜好了,有的喜欢在默认状态下不显示其它选项的内容,这个就是这种情况,仅供参考吧. 运行效果截图如下: 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o

点击页面任何位置隐藏div的实现方法_javascript技巧

实例如下: <include file="Public:header" /> <style type="text/css"> table{width:100%;margin: 0;} </style> <script type='text/javascript' src="/{:APP_PATH}/Public/js/unslider.min.js"></script> <scri

spinner-Spinner无法正常显示,点击变灰色

问题描述 Spinner无法正常显示,点击变灰色 求答,为什么spinner,什么都不显示,点击了它,屏幕会变暗 会不会是和自定义的下拉刷新这个控件冲突了??, 这是代码部分 private void initDetail(){ String[] details={"全部","手机/数码","电脑/家电","车辆/门票","文体/日用","书籍/影像" ,"门票/点卡"

VS2010 MFC ocx控件 button隐藏

问题描述 VS2010 MFC ocx控件 button隐藏 我的代码如下: 1.在初始化函数OnInitDialog中给按钮添加位图 if (m_button1.GetBitmap()==NULL) { m_button1.SetBitmap(::LoadBitmap(::AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP22))); //旋转90° ·······} 2.给菜单项"隐藏工具栏"添加事件处理程序,代码如下: void M

javascript carlengar 脚本日历的,不要正常显示,,要点击日历的左右按钮才能显示日期,求高手指教 [.NET

问题描述 javascript脚本日历的,不要正常显示,,要点击日历的左右按钮才能显示日期,求高手指教如何让它正常显示:日历代码:--------------------------<ScriptLANGUAGE="JavaScript">varmonths=newArray("一","二","三","四","五","六","七",&q