简体   繁体   English

如何消失文字检视?

[英]How to disappear the text view?

I have a problem when I try to disappear the text, I'm making a program with five buttons than change the background color (the buttons are down) but what I want to do is after click on the screen the text should disappear but when I click on the screen my buttons go up and I do know how to solve this problem. 我尝试消失文本时遇到问题,我正在制作一个具有五个按钮的程序,而不是更改背景颜色(按钮向下),但是我要做的是单击屏幕后文本应该消失,但是当我单击屏幕上的按钮,我确实知道如何解决此问题。

 myLayout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v){

             myText = (TextView) findViewById(R.id.textView1);
              myText.setVisibility(TextView.INVISIBLE);
                if(myLayout2.getVisibility()!=View.INVISIBLE)
                    myLayout2.setVisibility(View.INVISIBLE); 
                else
                    myLayout2.setVisibility(View.VISIBLE); 

            }

        });  

Use 采用

myText.setVisibility(View.INVISIBLE)

http://developer.android.com/reference/android/view/View.html#attr_android:visibility http://developer.android.com/reference/android/view/View.html#attr_android:visibility

visible     0    Visible on screen; the default value.
invisible   1    Not displayed, but taken into account during layout (space is left for it).
gone        2    Completely hidden, as if the view had not been added.

use View.INVISIBLE istead of View.GONE 使用View.INVISIBLE代替View.GONE

 myLayout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v){

             myText = (TextView) findViewById(R.id.textView1);
              myText.setVisibility(TextView.GONE);
                if(myLayout2.getVisibility()!=View.INVISIBLE )
                    myLayout2.setVisibility(View.INVISIBLE ); 
                else
                    myLayout2.setVisibility(View.VISIBLE); 

            }

        });  

您需要使用View.INIVISIBLE否则View.INIVISIBLE将消失,并且无法再次使其可见。

you should use this: 您应该使用此:

myText.setVisibility(View.INVISIBLE);

this hides the view from screen and keeps the references(margins) of the screen and also dependencies of other controls on this view.And if you are going to use this: 这将从屏幕上隐藏视图,并保留屏幕的引用(边距)以及该视图上其他控件的依赖关系。如果要使用此功能:

myText.setVisibility(View.GONE);

then the view will be vanished from screen and other controls dependancies will be cleared like if you have android:below or android:above so View.INVISIBLE is good practice. 那么该视图将从屏幕上消失,并且其他控件相关性也将被清除,例如如果您具有android:belowandroid:above那么View.INVISIBLE是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM