New ui-to set the visible and invisible view

Source: Internet
Author: User

New ui-to set the visible and invisible view

--Reprint Please indicate source: Coder-pig, welcome reprint, do not use for commercial use!


Piglet Android Development Exchange Group has been established, welcome everyone to join, both novice, rookie, Big God can, piglet a person's

Strength is limited after all, the writing out of things will certainly have a lot of flaws, welcome to point out, brainstorm, let the pig's blog

More detailed, help more people, O (∩_∩) o Thank you!

Piglet Android Development Exchange Group: Piglet Android Development Exchange Group Group number: 421858269

new Android UI Instance Daquan directory: http://blog.csdn.net/coder_pig/article/details/42145907



Introduction to this section:

Controlling the visibility of the view is invisible, which is often understood to be hidden, which is also one of the more properties we use when writing a layout.

For example, hide a button, show it in a specific situation, or click a button and then show the hidden ImageView or

ListView and so on, this property is still relatively common, it is necessary to understand the next! When you need a view, you don't want him to show up

the interface can be considered when using the Visibility This property!



1) XML Settings

android:visibility =" Gone "           //invisible, and does not occupy space
android:visibility =" Visible "         //Visible
android:visibility =" Invisible "     //not visible, but occupies space




p) Java Code Dynamic Settings

Suppose there is such a TextView TV in the interface;

tv.setvisibility(View.gone); //not visible, and does not occupy space, the constant value is: 0x00000008
tv.setvisibility(view.visible); //visible, constant value is: 0x00000000
tv.setvisibility(view.invisible); //not visible, but occupies space, constant value is: 0x00000004



3) Simple use example:

Run:


The use of this property is relatively simple to explain, just look at the sample code:

Activity_main.xml:

<relativelayout 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 "Tools:context = "Com.jay.example.visibilitydemo.MainActivity" > <textview android:id= "@+id/txtpage" android:layout _width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centerinparent= "true" Andro id:text= "1/10" android:textcolor= "#FF7878" android:textsize= "20sp"/> <button android:id= "@+ Id/btnpagebefore "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android:la Yout_alignparentleft= "true" android:layout_centervertical= "true" android:text= "prev"/> <butt On android:id= "@+id/btnpagenext" android:layout_width= "wrap_content" android:layout_height= "Wrap_cont Ent "android:layout_alignparentright="True "android:layout_centervertical=" true "android:text=" Next "/></relativelayout> 

Mainactivity.java:

Package Com.jay.example.visibilitydemo;import Android.app.activity;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public class Mainactivity extends Activity {private TextView txtpage;private Button btnpagenext ;p rivate Button btnpagebefore;private myclick myclick;private int page = 1; @Overrideprotected void OnCreate (Bundle savedi Nstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); FindViews (); setUpViews ();} private void Findviews () {txtpage = (TextView) Findviewbyid (r.id.txtpage); btnpagenext = (Button) Findviewbyid ( R.id.btnpagenext); Btnpagebefore = (Button) Findviewbyid (R.id.btnpagebefore);} private void Setupviews () {Myclick = new Myclick (); Btnpagenext.setonclicklistener (Myclick); Btnpagebefore.setonclicklistener (Myclick);} Private class Myclick implements Onclicklistener {@Overridepublic void OnClick (View v) {switch (V.getid ()) {case R.ID.BTNP Agenext:Btnpagebefore.setvisibility (view.visible);p age++;txtpage.settext (page + "/10"), if (page = = 10) { Btnpagenext.setvisibility (View.gone);} Break;case r.id.btnpagebefore:btnpagenext.setvisibility (view.visible);p age--;txtpage.settext (page + "/10"); page = = 0) {btnpagebefore.setvisibility (view.gone);} Break;}}}}




















New ui-to set the visible and invisible view

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.