View android: visibility attribute discussion, androidvisibility

Source: Internet
Author: User

View android: visibility attribute discussion, androidvisibility

The visibility attribute in Android VIEW, which is described in the API as follows:Controls the initial visibility of the view.[Control the initial visibility of the VIEW].

There are three parameters:

* The default value isVisible, Visible. Note that"Invisible"And"Gone. The description in the API is :"Invisible": The VIEW is not displayed, but its position remains in the layout. "Gone": Not displayed, and the VIEW is not added. For example, in A meeting, A did not come to participate, but the location of A remained there, but A was absent. "Gone" means that A does not attend the meeting and is not arranged at the time of arrangement.

The following is a simple example:

:

Code:

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 xmlns: tools = "http://schemas.android.com/tools" 4 android: layout_width = "match_parent" 5 android: layout_height = "match_parent" 6 android: orientation = "vertical" 7 tools: context = "$ {relativePackage }. $ {activityClass} "> 8 9 <TextView10 android: id =" @ + id/text1 "11 android: layout_width =" fill_parent "12 android: layout_height =" wrap_content "13 android: background = "@ color/red" 14 android: text = "@ string/view1"/> 15 16 <TextView17 android: id = "@ + id/text2" 18 android: layout_width = "fill_parent" 19 android: layout_height = "wrap_content" 20 android: background = "@ color/green" 21 android: text = "@ string/view2"/> 22 23 <TextView24 android: id = "@ + id/text3" 25 android: layout_width = "fill_parent" 26 android: layout_height = "wrap_content" 27 android: background = "@ color/blue" 28 android: text = "@ string/view3"/> 29 30 <LinearLayout31 android: id = "@ + id/btns" 32 android: layout_width = "fill_parent" 33 android: layout_height = "wrap_content" 34 android: orientation = "horizontal"> 35 36 <Button37 android: id = "@ + id/btn_visible" 38 android: layout_width = "wrap_content" 39 android: layout_height = "wrap_content" 40 android: onClick = "setVisible" 41 android: text = "@ string/btn1"/> 42 43 <Button44 android: id = "@ + id/btn_invisible" 45 android: layout_width = "wrap_content" 46 android: layout_height = "wrap_content" 47 android: onClick = "setInvisible" 48 android: text = "@ string/btn2"/> 49 50 <Button51 android: id = "@ + id/btn_gone" 52 android: layout_width = "wrap_content" 53 android: layout_height = "wrap_content" 54 android: onClick = "setGone" 55 android: text = "@ string/btn3"/> 56 </LinearLayout> 57 58 </LinearLayout>Main_layout 1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <resources> 3 <color name = "red"> # FF0000 </color> 4 <color name = "green"> #00FF00 </color> 5 <color name =" blue "> # 0000FF </color> 6 </resources> 7 8 9 <? Xml version = "1.0" encoding = "UTF-8"?> 10 <resources> 11 12 <string name = "app_name"> VisiblityApp </string> 13 <string name = "view1"> View1 </string> 14 <string name = "view2 "> View2 </string> 15 <string name =" view3 "> View3 </string> 16 <string name =" btn1 "> Visible </string> 17 <string name = ""btn2"> Invisible </string> 18 <string name = "btn3"> Gone </string> 19 20 </resources>Color. xml string. xml 1 public class MainActivity extends Activity {2 private TextView textView2; 3 4 @ Override 5 protected void onCreate (Bundle savedInstanceState) {6 super. onCreate (savedInstanceState); 7 setContentView (R. layout. activity_main); 8 textView2 = (TextView) findViewById (R. id. text2); 9} 10 11 public void setVisible (View v) {12 textView2.setVisibility (View. VISIBLE); 13} 14 15 public void setInvisible (View v) {16 textView2.setVisibility (View. INVISIBLE); 17} 18 19 public void setGone (View v) {20 textView2.setVisibility (View. GONE); 21} 22 23}MainActivity

 

* This ends.

Extra article: I think I have been away from J2EE for two years. I have experienced a lot in the past two years and have seen a lot in the past two years. Maybe all of this is self-defeating... Well, we have to continue. Let's go step by step. In the days to come, I will write an article every day to record the Android learning path.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.