我需要为我的活动的纵向和横向方向应用不同的布局.此外,如果方向是肖像,我需要显示警报.
我在AndroidManifest中指定了android:configChanges =“orientation | keyboardHidden”.我也像这样重写onConfigurationChanged方法:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
Log.d("tag","config changed");
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT)
Log.d("tag","Portrait");
else if (orientation == Configuration.ORIENTATION_LANDSCAPE)
Log.d("tag","Landscape");
else
Log.w("tag","other: " + orientation);
....
}
从横向旋转到纵向日志时看起来像:
config changed
Portrait
但是,当从纵向变为风景时,它看起来像
config changed
Portrait
config changed
Landscape
为什么onConfigurationChanged被调用两次?我怎么能避免呢?