inflate, findViewById与setContentView的区别与联系

mac2022-06-30  26

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_news_content); viewFlipperNewsUi = (ViewFlipper) findViewById(R.id.viewflipper_news_ui); inflater = getLayoutInflater(); View rLNewsUi = inflater.inflate(R.layout.news_body, null); viewFlipperNewsUi.addView(rLNewsUi); } 1、 inflate是用来找layout下布局文件,并实例化;而findViewById是找布局文件下的具体widget。

2、setContentView()一旦调用, layout就会立刻显示UI;而inflate只会把Layout形成一个以view类实现成的对象,有需要时再用setContentView(view)显示出来。

转载于:https://www.cnblogs.com/jinhong-lu/p/4559482.html

最新回复(0)