zoukankan      html  css  js  c++  java
  • android和view相关的东西

    findViewById(R.id.xxxx),把xml里面的控件根据id绑定到类成员变量,适用于普通控件和布局

    LayoutInflater,用于把布局xml里面的东西实例化(会重新实例化,和findViewById不同),sample代码如下

    LayoutInflater inflator = getLayoutInflater();

    //注意,这里参数是layout,不是id
    RelativeLayout layout = (RelativeLayout)inflator.inflate(R.layout.activity_main, null);
            
     TextView aTextView = new TextView(this);
    aTextView.setWidth(100);
    aTextView.setHeight(100);
    aTextView.setText("asdasdasdasd");
    layout.addView(aTextView);
            

    //采用LayoutInflater的需要重新设置布局才有效果。
    setContentView(layout);

    附三种使用LayoutInflater的方法

    LayoutInflater inflater = LayoutInflater.from(this);
    View layout = inflater.inflate(R.layout.main, null);
     
    LayoutInflater inflater = getLayoutInflater();  
    View layout = inflater.inflate(R.layout.main, null);
     
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);  
    View layout = inflater.inflate(R.layout.main, null); 

  • 相关阅读:
    Windows下安装redis,并与PHP使用
    php中的一些小细节(1)
    MIME类型
    Oracle与SQL Server事务处理的比较
    php+memcached缓存技术实例
    B-树
    平衡二叉树(AVL)
    树--二叉查找树(二叉排序树)
    八种常见的排序算法
    反转一个值中的最后n位
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/3093761.html
Copyright © 2011-2022 走看看