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); 

  • 相关阅读:
    ssm框架实现多条件查询分页(模拟百度算法)
    spring与mybatis的整合
    spring入门
    mybatis foreach标签用法
    图书借阅系统简易异步分页源码
    Jquery常用选择器
    mvc
    Java连接数据库 jdbc
    java学习线路
    Mybatis传递多个参数的几种方式
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/3093761.html
Copyright © 2011-2022 走看看