我的问题是onConfigurationChanged没有被调用。
代码如下:
public void onConfigurationChanged(Configuration newConfig) {
Log.i("onconfig", "#### CALLED!");
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
LinearLayout listContainer = (LinearLayout)findViewById(R.id.list_container);
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
listContainer.setOrientation(LinearLayout.HORIZONTAL);
}
else{
listContainer.setOrientation(LinearLayout.VERTICAL);
}
// end if else
}
// end of on configuration changed
在清单中我有:
<activity
android:name=".FirstListActivity"
android:label="@string/title_activity_fruits_list"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
感谢任何可以提供帮助的人。
答案 0 :(得分:2)
在screenSize
属性标记中添加android:configChanges
值。更多阅读this answer
答案 1 :(得分:0)
请参阅此答案:https://stackoverflow.com/a/6109206/1182515
您是否在onCreate中使用此方法?
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
使用时,您不会收到方向更改。
尝试链接帖子中给出的解决方案。