2012-03-28 33 views

回答

2

你只是錯過了,這是片段文件中的第一個代碼段:

public static class ExampleFragment extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.example_fragment, container, false); 
    } 
} 

它採用了(提供)LayoutInflater膨脹的佈局,在這種情況下,命名爲example_fragment.xml(膨脹表示解析XML並生成一個佈局結構)。所以是的,當然有可能。

基本上所有你需要做的就是從onCreateView()回報您的片段佈局。你如何生成它是由你自己決定的,既然你得到了一個inflater,它的目的也是使用XML。

+0

謝謝,完美! – 2012-03-28 16:02:41

相關問題