Android,UI 在程式中即時加上其他的UI

Android,UI 在程式中即時加上其他的UI

    柯博文 在下面介紹, 如何在Android UI 在程式中即時加上其他的UI

        View tmpView;   
            tmpView = inflater.inflate(R.layout.login, null);    
           getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,    ViewGroup.LayoutParams.FILL_PARENT));    
           Button buttonView = new Button(this);    
           buttonView.setText("Button " );   
          getWindow().addContentView(buttonView, 
               new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT    ViewGroup.LayoutParams.WRAP_CONTENT  ));    
    
    

        
           
              // 按鈕
              LayoutInflater inflater = getLayoutInflater();
              View tmpView;
              tmpView = inflater.inflate(R.layout.login, null);
              getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
              ViewGroup.LayoutParams.FILL_PARENT));
              
              Button buttonView = new Button(this);
              buttonView.setText("Button " );
              
              getWindow().addContentView(buttonView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                      ViewGroup.LayoutParams.WRAP_CONTENT  ));
              
              
              
              //文字
              TextView textView = new TextView(this);
              textView.setText("Text View " );
              
              
              
    
              
              
              @SuppressWarnings("deprecation")
    		AbsoluteLayout.LayoutParams abs_params = 
                  new AbsoluteLayout.LayoutParams(
                      //width in pixels
                      100,
                      //height in pixels
                      100, 100, 100
                  );          
              getWindow().addContentView(textView,abs_params);
           
    
              
              
              
              
              AbsoluteLayout as = new AbsoluteLayout(this);
    
              TextView tvTop = new TextView(this);
              tvTop.setText("top");
              tvTop.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 0));
    
              TextView tvMid = new TextView(this);
              tvMid.setText("middle");
              tvMid.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 80));
    
              
              TextView tvright = new TextView(this);
              tvright.setText("right");
              tvright.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 200, 80));
    
              
              
              TextView tvBot = new TextView(this);
              tvBot.setText("bottom");
              tvBot.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 180));
    
              as.addView(tvTop);
              as.addView(tvMid);
              as.addView(tvright);
              as.addView(tvBot);
    
    
              
              getWindow().addContentView(as,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            		                  ViewGroup.LayoutParams.WRAP_CONTENT  ));