zoukankan      html  css  js  c++  java
  • 动态生成linearLayout

    LinearLayout linearLayout=new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams param=
    new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(param);
    // 每个layout都是一个ViewGroup
    // linearLayout.addView(child);
    // linearLayout.removeView(view);

    TextView textview=new TextView(this);
    textview.setText("hello world");
    textview.setTextSize(30);

    textview.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

    ViewGroup group = (ViewGroup) v.getParent();
    TextView textview = new TextView(MainActivity.this);
    textview.setText("this is onclickListener");
    textview.setTextSize(30);
    textview.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    ViewGroup group = (ViewGroup) v.getParent();
    group.removeView(v);
    }
    });

    group.addView(textview);

    }
    });



    linearLayout.addView(textview);
    this.setContentView(linearLayout);//将linearlayout添加到视图中
    }

  • 相关阅读:
    函数方法与面向对象
    seleniums私房菜系列一 ---- selenium简介
    MySQL图形化管理工具
    存储引擎
    mysql自定义函数
    加密函数
    mysql聚合函数
    mysql信息函数
    mysql日期时间函数(常用的)
    mysql比较运算符和函数
  • 原文地址:https://www.cnblogs.com/guozhiping/p/5006768.html
Copyright © 2011-2022 走看看