zoukankan      html  css  js  c++  java
  • Android动态添加布局

    //1.利用LayoutInflater的inflate动态加载XML
      mLinearLayout = (LinearLayout)findViewById(R.id.LinearLayout_ID);
      LayoutInflater layoutInflater = LayoutInflater.from(context);
      View view = layoutInflater.inflate(resource--需要加载的XML, null);
      XML:resource = R.layout.XML-Name;
      mLinearLayout.removeAllViewsInLayout();移除当前LinearLayout的内容
      mLinearLayout.addView(view);添加XML到LinearLayout
    设置Width和Hight:
        LinearLayout.LayoutParams.FILL_PARENT、mLinearLayout.getLayoutParams().width等
    另:
    mLinearLayout.addView(v,
        new LinearLayout.LayoutParams(mLinearLayout.getLayoutParams().width, 
        mLinearLayout.getLayoutParams().height));
    
    //2.利用View.inflate加载xml
     setContentView(R.layout.layout_1); 
         LinearLayout ll = (LinearLayout) findViewById(R.id.box_1); 
         View vv = View.inflate(this, R.layout.layout_2, null); 
         ll.addView(vv,       new LinearLayout.LayoutParams   ll.getLayoutParams ().width,ll.getLayoutParams().height));
  • 相关阅读:
    连续型随机变量
    离散型随机变量
    vue1.0生命周期
    vue2.0生命周期函数
    vue2.0 vue.set()
    vue2.0 vue.extend()的拓展
    vue2.0 自定义指令详解
    vue2.0 v-model指令
    vue2.0排序应该注意的问题
    vue2.0版本指令v-if与v-show的区别
  • 原文地址:https://www.cnblogs.com/niray/p/3857262.html
Copyright © 2011-2022 走看看