Bonjour à tous,

Dans mon fichier XML main.xml j'ai :
- une image qui s'affiche sur la totalité de mon écran (fond d'écran)
- puis une partie supérieure de l'IHM plusieurs ImageView et Button.
- et enfin une partie inférieure de l'IHM qui affiche soit :
+ android.support.v4.view.ViewPager (composé de deux fragments)
+ un autre écran (fenetre_erase.xml composé de plusieurs Button)

J'ai un répertoire /layout pour l'affichage en mode paysage où j'ai placé les fichiers (main.xml, layout_fragment1.xml, layout_fragment2.xml et fenetre_erase.xml) ainsi qu'un répertoire /drawable où sont placées mes images dimensionnées pour le mode paysage
J'ai un répertoire /layout-port pour l'affichage en mode portrait où j'ai placé les mêmes fichiers (main.xml, layout_fragment1.xml, layout_fragment2.xml et fenetre_erase.xml), j'ai juste modifié la position de chaque composant dans ces fichiers XML et un répertoire /drawable-port où sont placées les mêmes images que dans /drawable mais avec des dimensions adaptées pour le mode paysage.

main.xml mode paysage :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff0000">
    <ImageView
		android:id="@+id/IdImgFondEcran"
		android:src="@drawable/fond_ecran"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_gravity="center"
		/>
	<Button
		android:id="@+id/IdButonErase"
		android:background="@drawable/button_erase"
		android:onClick="fonctionErase"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="25px"
		android:layout_marginLeft="4px"
		/>
	<ImageView
		android:id="@+id/IdIconBatteryLevel"
		android:src="@drawable/icon_battery"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginTop="34px"
		android:layout_marginLeft="1179px"
		/>
         <FrameLayout android:id="@+id/IdLayoutMain" 
    	        android:layout_width="wrap_content"
    	        android:layout_height="wrap_content"
    	        android:layout_marginTop="250px">
  			<android.support.v4.view.ViewPager
  			android:id="@+android:id/viewpager"
  			android:layout_width="wrap_content"
 			android:layout_height="wrap_content"
  			/>
  	</FrameLayout>
        <FrameLayout android:id="@+id/IdLayoutErase" 
    	        android:layout_width="wrap_content"
    	        android:layout_height="wrap_content"
    	        android:layout_marginTop="250px">
    	        <include android:id="@+id/erase" layout="@layout/fenetre_erase"/>
  	</FrameLayout>
</FrameLayout>
J'ai également une classe PagerAdapter dérivant de FragmentPagerAdapter et enfin la classe ViewPagerFragmentActivity dérivant de FragmentActivity.

Au démarrage de l'application, j'affiche dans la partie inférieure le premier fragment (layout_fragment1.xml du répertoire /layout) en mode paysage. Quand je passe en mode portrait, j'affiche le fragment adapté au mode portrait (layout_fragment1.xml du répertoire /layout-port).

Jusqu'ici tout va bien...
Jusqu'ici tout va bien...

Mais lorsque je suis sur le fragment2 (layout_fragment2.xml) ou sur l'écran fenetre_erase.xml en mode paysage et que je passe en mode portrait (ou au passage du mode portrait au mode paysage), l'application affiche le fragment1 (layout_fragment1.xml).

Je voudrais afficher la page courante lors d'un changement d'orientation de ma tablette. C'est à dire, quand je suis sur le fragment2 layout_fragment2.xml en mode paysage et que je change d'orientation, mode portrait, je voudrais afficher le fragment2 (layout_fragment2.xml adapté au mode portrait) et non pas afficher le fragment1 (layout_fragment1.xml).

Avez vous des solutions ? des conseils ?