我有一项活动,当我更改方向时,不会调用onConfigurationChanged()
。
请帮我解决这个问题。我试过但找不到原因。
代码:
@Override
public void onConfigurationChanged(Configuration configure){
super.onConfigurationChanged(configure);
setLayout(); //Set the layout.
//Get the orientation of the device and set the gravity according to that.
if(configure.orientation == Configuration.ORIENTATION_PORTRAIT) {
parentLinearLayout.setGravity(Gravity.CENTER_VERTICAL);
} else if(configure.orientation == Configuration.ORIENTATION_LANDSCAPE) {
parentLinearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
}
}
<activity android:name=".AddProductsActivity"
android:configChanges="orientation|keyboardHidden"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
答案 0 :(得分:18)
如果您定位API 13
或更高,则必须添加screenSize
。请更改此行:
android:configChanges="orientation|keyboardHidden"
到
android:configChanges="orientation|screenSize|keyboardHidden"