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
Répondre
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
}
}
merci cela a fonctionné – bhaskar
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
}
Pour cet androïde fonctionnalité fournit Sliding mise en page du volet SlidingPaneLayout
et regarder ce tutoriels aussi tutoriel officiel google développeurs https://www.youtube.com/watch?v=Jl3-lzlzOJI&t=1007s
http://stackoverflow.com/questions/18268218/change-screen-orientation-programatically-using-a-bouton – Apurva