Use a folder layout-land and layout-port them is a copy main.xml.
public void onSensorChanged(SensorEvent e) {
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
if(event.values[0] >= 8)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
When you switch the screen is the establishment of two layers on each other. I use android:configChanges="orientation|keyboardHidden"
Help me please if you can give an example. I would be very grateful.