[Android] Core Method of interface switch, android Switch

Source: Internet
Author: User

[Android] Core Method of interface switch, android Switch

Based on the split Interface

 

 

View ==> ViewGroup ==> RelativeLayout. The subject uses RelativeLayout as the placeholder.

 

Difference between View and ViewGroup: ViewGroup has the unique addView () and removeView () methods. After RelativeLayout is added to the View, the latter will overwrite the previous View. After LinearLayout is added to the View, will be discharged sequentially, not suitable

 

Design principle:

Data processing in the tree structure follows the combined design mode.

 

 

Locate the RelativeLayout object of the subject and add the View object.

Switch the second interface two seconds later, and use Handler to send delayed messages to simulate Switching

RelativeLayout object. Add the second View object.

 

Problem:

 

MainActivity. java

Private Handler handler = new Handler () {@ Override public void handleMessage (Message msg) {loadMemberView () ;};/*** initialize the subject */public void initMiddle () {mainContainer = (RelativeLayout) findViewById (R. id. il_main); loadLoginView (); handler. sendEmptyMessageDelayed (1, 2000);}/*** load login interface */private void loadLoginView () {View child = new IndexView (this ). getLoginView (); mainContainer. addView (child);}/*** load member interface */private void loadMemberView () {View child = new IndexView (this ). getMemberView (); mainContainer. removeAllViews (); mainContainer. addView (child );}

IndexView. java

Package com. tsh. lottery. views; import android. content. context; import android. view. view; import android. widget. textView;/*** interface * @ author taoshihan **/public class IndexView {private Context context; public IndexView (Context context) {this. context = context;}/*** get login interface * @ return */public View getLoginView () {TextView TV = new TextView (context); TV. setText ("My login interface"); return TV;}/*** get Member interface * @ return */public View getMemberView () {TextView TV = new TextView (context); TV. setText ("I am a Member interface"); return TV ;}}

 

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.