我有一个活动,当我改变方向时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" />