New UI-set visible and invisible view, newui-view visible

Source: Internet
Author: User

New UI-set visible and invisible view, newui-view visible

New UI-set visible and invisible View

-- Reprinted please indicate the source: coder-pig. You are welcome to repost it. Please do not use it for commercial purposes!


The piggy Android development and exchange group has been established. You are welcome to join us. You can be a newbie, cainiao, or a great god.

After all, the power is limited. There will certainly be a lot of flaws in writing. You are welcome to point out, brainstorm, And let pig's blog post.

For more details, help more people, O (∩ _ ∩) O thank you!

Piggy Android Development Exchange Group: Piggy Android Development Exchange Group No.: 421858269

New Android UI instance Daquan Directory: http://blog.csdn.net/coder_pig/article/details/42145907



This section introduces:

Controlling the visibility of a View is invisible. It can be understood as hiding. This is also an attribute that we use when writing a painting layout,

For example, hide a button to display it in a specific situation, or click a button to display the hidden ImageView or

ListView and so on. This attribute is still quite common. You need to know it! When you need a View, you do not want it to be displayed

You can use the Visibility attribute on the interface!



1) XML settings

Android: visibility = "gone" // invisible and not occupying space
Android: visibility = "visible" // visible
Android: visibility = "invisible" // invisible, but occupying space




2) Dynamic Setting of Java code

Suppose there is such a TextView TV in the interface;

TV. setVisibility (View. GONE); // invisible and not occupying space. The constant value is 0x00000008.
TV. setVisibility (View. VISIBLE); // VISIBLE, constant value: 0x00000000
TV. setVisibility (View. INVISIBLE); // INVISIBLE, but occupying space, constant value: 0x00000004



3) simple example:

Run:


The usage of this attribute is simple, so let's 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 "android: 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: layout_alignParentLeft = "true" android: layout_centerVertical = "true" android: text = "Previous Page"/> <Button android: id = "@ + id/btnPageNext" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentRight = "true" android: layout_centerVertical = "true: text = "next page"/> </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;private Button btnPageBefore;private MyClick myClick;private int page = 1;@Overrideprotected void onCreate(Bundle savedInstanceState) {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.btnPageNext:btnPageBefore.setVisibility(View.VISIBLE);page++;txtPage.setText(page + "/10");if(page == 10){btnPageNext.setVisibility(View.GONE);}break;case R.id.btnPageBefore:btnPageNext.setVisibility(View.VISIBLE);page--;txtPage.setText(page + "/10");if(page == 0){btnPageBefore.setVisibility(View.GONE);}break;}}}}




















Related Article

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.