LinearLayout addView 应该是这样写的.

来源:互联网 发布:linux telent 安装 编辑:程序博客网 时间:2024/05/29 09:36

      1 parentview 如果来自res/layout/.xml  , 需用layoutinflater.inflate 之后, addView.

         错误的: parentlayout = findviewbyid(R.layout.xxx);   这样是加载不上的.  错误在于 findviewbyid() 需要一个主View, 就是在哪个View上面 findviewbyid().

                          在setContentView之前, 或者指定 WhichView.findviewbyid().  findviewbyid 不好用.... 

                            

        正确的:

            LayoutInflater inflater = LayoutInflater.from(this);

            LinearLayout ly = (LinearLayout)inflater.inflate(R.layout.main_test_ly, null);
            ly.addView(view);
            setContentView(ly);
0 0