getLayoutInflater() 以及findViewById(R.id.outerlayout)区别
2014-02-27 13:28
465 查看
mainLayout = (LinearLayout) getLayoutInflater().inflate(
R.layout.calendar_main, null); 通过这种方式初始化布局文件; 其中R.layout.calendar_main 是个在layout 下面的布局文件;
觉得 getLayoutInflater() 这种就是直接加载布局文件; 返回的是一个vew 对象;
一般是R.layout.id; 通过这种方式找到的一般就是个布局文件; 比如LinearLayout;
而findview by id 是 可以是 activity.findview by id() 也可以是 view.findviewbyid; 这种可以返回一个 布局文件; 比如LinearLayout 或者是一个TextView 等等;
似乎可以是它的孩子或者是孩子的孩子的id; 具体的下面的例子自己体会下;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.rili);
// --------------begin--------
// LinearLayout calendarLayout = (LinearLayout) getLayoutInflater()
// .inflate(R.id.right, null); // 通过这种方式初始化布局文件;
LinearLayout global = (LinearLayout) getLayoutInflater().inflate(
R.layout.activity_main, null);
// 其中R.layout.calendar_main
// 是个在layout 下面的布局文件;
LinearLayout relativeLayout = (LinearLayout) global
.findViewById(R.id.outerlayout);
LinearLayout rili = (LinearLayout) getLayoutInflater().inflate(
R.layout.rili, null); // 通过这种方式初始化布局文件;
relativeLayout.addView(rili);
// global.addView(rili);
// 其中R.layout.calendar_main
// 是个在layout 下面的布局文件;
setContentView(global);
gestureDetector = new GestureDetector(this);
flipper = (ViewFlipper) findViewById(R.id.flipper);
flipper.removeAllViews();
calV = new CalendarView(this, getResources(), jumpMonth, jumpYear,
year_c, month_c, day_c);
addGridView();
gridView.setAdapter(calV);
flipper.addView(gridView, 0);
topText = (BorderText) findViewById(R.id.toptext);
addTextToTopTextView(topText);
}
R.layout.calendar_main, null); 通过这种方式初始化布局文件; 其中R.layout.calendar_main 是个在layout 下面的布局文件;
觉得 getLayoutInflater() 这种就是直接加载布局文件; 返回的是一个vew 对象;
一般是R.layout.id; 通过这种方式找到的一般就是个布局文件; 比如LinearLayout;
而findview by id 是 可以是 activity.findview by id() 也可以是 view.findviewbyid; 这种可以返回一个 布局文件; 比如LinearLayout 或者是一个TextView 等等;
似乎可以是它的孩子或者是孩子的孩子的id; 具体的下面的例子自己体会下;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.rili);
// --------------begin--------
// LinearLayout calendarLayout = (LinearLayout) getLayoutInflater()
// .inflate(R.id.right, null); // 通过这种方式初始化布局文件;
LinearLayout global = (LinearLayout) getLayoutInflater().inflate(
R.layout.activity_main, null);
// 其中R.layout.calendar_main
// 是个在layout 下面的布局文件;
LinearLayout relativeLayout = (LinearLayout) global
.findViewById(R.id.outerlayout);
LinearLayout rili = (LinearLayout) getLayoutInflater().inflate(
R.layout.rili, null); // 通过这种方式初始化布局文件;
relativeLayout.addView(rili);
// global.addView(rili);
// 其中R.layout.calendar_main
// 是个在layout 下面的布局文件;
setContentView(global);
gestureDetector = new GestureDetector(this);
flipper = (ViewFlipper) findViewById(R.id.flipper);
flipper.removeAllViews();
calV = new CalendarView(this, getResources(), jumpMonth, jumpYear,
year_c, month_c, day_c);
addGridView();
gridView.setAdapter(calV);
flipper.addView(gridView, 0);
topText = (BorderText) findViewById(R.id.toptext);
addTextToTopTextView(topText);
}
相关文章推荐
- [Android]inflate方法与 findViewById 方法区别 | LayoutInflater的inflate函数用法详解
- [Android]inflate方法与 findViewById 方法区别 | LayoutInflater的inflate函数用法详解
- Android] setContentView和inflater区别以及findViewById和inflater的区别
- Android中setContentView、addContentView、inflate、LayoutInflater和findViewById()区别
- [Android]inflate方法与 findViewById 方法区别 | LayoutInflater的inflate函数用法详解
- LayoutInflater和findViewById的区别
- [Android] setContentView和inflater区别以及findViewById和inflater的区别
- android程序 在View view = LayoutInflater.from(getContext()).inflate(resourceId, nul
- LayoutInflater与findViewById的用法
- Android的LayoutInflater和findViewById()的详解
- LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。 但他是找XML文件并实例化
- ayoutInflater和findViewById() 的区别
- LayoutInflater & findViewById
- Inflater与findViewById()区别
- LayoutInflater 的基本使用; LayoutInflater ,setContentView,findViewById三者的对比。
- Inflater与findViewById()区别
- android LayoutInflater、setContentView、findviewbyid 区分解析
- Inflater与findViewById()区别
- $("#id")与document.getElementById("id")的区别以及相互转化
- Android(java)学习笔记114:LayoutInflater和findViewById