• 带视图缓存的动态布局


    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.LinearLayout;
    
    public class PadTestActivity extends Activity {
    
        View chacheView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // setContentView(R.layout.main);
    
            LayoutInflater inflater = LayoutInflater.from(this);
            final View mainView = inflater.inflate(R.layout.main, null);
            // Add first page
            LinearLayout myFirst = (LinearLayout) inflater.inflate(R.layout.first, null).findViewById(R.id.myFirst);
            LinearLayout layoutFirst = (LinearLayout) mainView.findViewById(R.id.LayoutFirst);
            layoutFirst.removeAllViews();
            layoutFirst.addView(myFirst); // Show the page first
            
            // Add second page
            LinearLayout mySecond = (LinearLayout) inflater.inflate(R.layout.second, null).findViewById(R.id.mySecond);
            LinearLayout layoutSecond = (LinearLayout) mainView.findViewById(R.id.LayoutSecond);
            layoutSecond.removeAllViews();
            layoutSecond.addView(mySecond);
            
            // Add third page
            LinearLayout myThird = (LinearLayout) inflater.inflate(R.layout.third, null).findViewById(R.id.myThird);
            LinearLayout layoutThird = (LinearLayout) mainView.findViewById(R.id.LayoutThird);
            layoutThird.removeAllViews();
            layoutThird.addView(myThird);
    
            setContentView(mainView);
            
            chacheView = myFirst;
    
            Button btnDelete = (Button) mainView.findViewById(R.id.btnDelete);
            btnDelete.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
    
                    LinearLayout layoutFirst = (LinearLayout) mainView.findViewById(R.id.LayoutFirst);
                    layoutFirst.removeAllViews();
                }
            });
            
            Button btnAdd = (Button) mainView.findViewById(R.id.btnAdd);
            btnAdd.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    
                    LinearLayout layoutFirst = (LinearLayout) mainView.findViewById(R.id.LayoutFirst);                
                    if (chacheView != null) {
                        layoutFirst.addView(chacheView);
                    }                            
                }
            });
        }
        
    }
  • 相关阅读:
    Python 学习笔记(七)Python字符串(三)
    Python 学习笔记(七)Python字符串(二)
    Python 学习笔记(六)Python第一个程序
    Python 学习笔记(五)常用函数
    Python 学习笔记(四)数字(二)
    行为型模式之责任链模式
    python_frm组件
    django之models学习总结
    HTTP协议
    事件委托
  • 原文地址:https://www.cnblogs.com/makeryan/p/2495751.html
Copyright © 2020-2023  润新知