2013.10.9 Difference between Activity and FragmentActivity, getMetrics

1,

Difference between Activity and FragmentActivity

FragmentActivity is a subclass of Activity that was built for the Android Support Package.

The FragmentActivity class adds a couple new methods to ensure compatibility with older versions of Android, but other than that, there really isn't much of a difference between the two. Just make sure you change all calls to getLoaderManager() and getFragmentManager() to getSupportLoaderManager() andgetSupportFragmentManager() respectively.


link:  http://stackoverflow.com/questions/10477997/difference-between-activity-and-fragmentactivity

总结:在android 3.0(api 11)之前的平台上要使用Fragment,需要包 support.v4,这时要用FragmentActivity,getSupportFragmentManager(),Fragment,都用support.v4下的。

在3.0以上的平台上,直接用Activity, getFragmentManager(),Fragment,用的是android.app.Fragment

2,
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
通过第2行代码可以给dm设置许多属性,getMetrics的源码是这样的
129    public void getMetrics(DisplayMetrics outMetrics) {
130        outMetrics.widthPixels  = getWidth();
131        outMetrics.heightPixels = getHeight();
132        outMetrics.density      = mDensity;
133        outMetrics.densityDpi   = (int)((mDensity*DisplayMetrics.DENSITY_DEFAULT)+.5f);
134        outMetrics.scaledDensity= outMetrics.density;
135        outMetrics.xdpi         = mDpiX;
136        outMetrics.ydpi         = mDpiY;
137    }


 通过为DisplayMetrics对象的public成员变量赋值来实现对dm的改变。而不是通过返回一个新的 
  DisplayMetrics对象。 
  

你可能感兴趣的:(2013.10.9 Difference between Activity and FragmentActivity, getMetrics)