fragment,preference
一、fragment:译碎片,google目的:为了满足应用程序适应不同分析率的屏幕
1、必须依赖于activity存在
2、生命周期:
activtiy: onCreate----------------------------onstart-----------onResume-------------onPause---------------onStop-------------------onDestory
fragement: onTouch---onCreate----onCreateView-----onStart----------onResume-------------onPause---------------onStop------onDestoryView---onDestory
onCreateView:此方法提供ViewGroup,用来绑定fragment,然后返回这个layout对象
二、preference:以sharePreference的存储原理保存记录控件状态
三、用法:
继承PreferenceActivity
public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.preference_headers, target);
//addPreferencesFromResource(R.xml.fragmented_preferences); 在目前sdk中该方法不能在Preference用了,可在fragment中实现
}
public static class PrefsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); } }