我是一个有用的助手,可以为您进行翻译。以下是您需要翻译的内容:“我有一个活动,在这个活动中当我改变方向时,
“代码:”
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" />