LayoutInflater的做用

LayoutInflater的做用是導入界面,說白了就是查找layout中的.xml界面並導入。以下:this

public class MainActitivity extends Acticity{xml

  TextView textView;ci

  public void onCreate(Bundle savedInstanceState){it

    super.onCreate(savedInstanceState);class

    //setContentView(R.layout.activity_main);layout

    textView=(TextView)findViewById(R.id.textView);activity

    

    LayoutInflater layoutInflater=LayoutInflater.from(this);view

    View view=layoutInflater.inflate(R.layout.activity_main,null);vi

    setContentView(view);界面

  }

}

以上類中,setContentView(R.layout.activity_main)是能夠被

 LayoutInflater layoutInflater=LayoutInflater.from(this);

    View view=layoutInflater.inflate(R.layout.activity_main,null);

    setContentView(view);

代替的,但其做用不只如此,若是想要到導入新的界面,徹底可用LayoutInflater

相關文章
相關標籤/搜索