2016-04-11 1 views
0

J'ai un activity dans lequel je charge un fragment. Disons que j'ai deux sections à l'intérieur fragment layout (section A et B), mais pendant que je passe en mode paysage, je dois montrer seulement la section A. Comment vais-je savoir le changement d'orientation à l'intérieur du fragment.Manipulation de l'orientation à l'intérieur du fragment

+0

http://stackoverflow.com/questions/18268218/change-screen-orientation-programatically-using-a-bouton – Apurva

Répondre

0

vous pouvez remplacer onConfigurationChanged pour être informé lorsque l'on change d'orientation ajouter du code ci-dessous dans votre classe fragment:

@Override public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    if(newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){ 
     //landscape 
    }else{ 
     //portrait 
    } 
} 
+0

merci cela a fonctionné – bhaskar

0

Lorsque l'orientation de l'écran est modifié, le Fragment sera détruit et créé à nouveau, si onDestroy() et onCreate() sont appelés. dans votre onCreate() ou onCreateView() (ou partout où vous avez besoin), vous pouvez vérifier la rotation de l'écran en cours avec le code suivant:

int screenRotation = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); 
     if(screenRotation == Surface.ROTATION_90 || screenRotation == Surface.ROTATION_270) { 
      //LANDSCAPE 
     } else { 
      //PORTRAIT 
     }