Bonsoir à tous,

J'ai un layout qui comprend une RelativeView.
En raisons de contrainte techniques j'étais amené à créer des vues de façon dynamique et l'ajouter à ma relativeView

Maintenant ce que je souhaiterai réaliser c'est positionner une RelativeLayout en xml en dessous de celle que j'ai crée, or lorsque je position en xml mon RelativeLayout au runTime le positionnement ne se fait pas correctement.

Layout code XML:
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
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 
    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
 
        <RelativeLayout
            android:id="@+id/container_imge_product"
            android:layout_width="200dp"
            android:layout_height="300dp"
            android:layout_below="@+id/h1_title_detail_commande"
            android:layout_centerHorizontal="true"
            android:background="@drawable/corner_layout_orange" >
        </RelativeLayout>
 
      <RelativeLayout
            android:id="@+id/na"
            android:layout_width="222dp"
            android:layout_height="200dp"
            android:layout_below="@+id/container_imge_product"
            android:background="@drawable/corner_layout_orange" >
        </RelativeLayout> 
    </RelativeLayout>
 
</ScrollView>
Code Java:
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.container_imge_product);
        relativeLayout.setId(1);
        relativeLayout.setPadding(20, 20, 20, 20);
 
        for (int i = 0; i <3; i++) {
            RelativeLayout firstLayout = new RelativeLayout(this);
            RelativeLayout.LayoutParams firstLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
            firstLayout.setId(1 +i);
            firstLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
 
            	firstLayoutParams.addRule(RelativeLayout.BELOW, firstLayout.getId() -1);
            	firstLayoutParams.setMargins(0, 20, 0, 0);
            	firstLayoutParams.addRule(RelativeLayout.ALIGN_LEFT, firstLayout.getId() -1);
 
 
 
            firstLayout.setLayoutParams(firstLayoutParams);
 
            ImageView imageView = new ImageView(this);
            imageView.setImageDrawable(getResources().getDrawable(R.drawable.play_station_4));
            RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
            imageView.setId(1);
            imageViewParams.addRule(RelativeLayout.ALIGN_LEFT);
            imageViewParams.addRule(RelativeLayout.ALIGN_TOP);
            imageView.setLayoutParams(imageViewParams);
 
 
            TextView title_txt = new TextView(this);
            RelativeLayout.LayoutParams title_txtParams = new RelativeLayout.LayoutParams(250,RelativeLayout.LayoutParams.WRAP_CONTENT);
            title_txtParams.addRule(RelativeLayout.RIGHT_OF, imageView.getId());
            title_txtParams.addRule(RelativeLayout.ALIGN_TOP);
            title_txt.setId(8);
            title_txt.setLayoutParams(title_txtParams);
            title_txtParams.setMargins(10, 0, 0, 0);
            title_txt.setText("Sisley Chantal, sac porté main - Noir (Black, Taille unique)");
 
            TextView price_txt = new TextView(this);
            RelativeLayout.LayoutParams price_txtParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
            price_txtParams.addRule(RelativeLayout.RIGHT_OF, title_txt.getId());
            price_txtParams.addRule(RelativeLayout.ALIGN_TOP);
            price_txt.setId(5);
            price_txt.setLayoutParams(price_txtParams);
            price_txtParams.setMargins(20, 0, 0, 0);
            price_txt.setText("EUR 75,00");
 
 
            TextView quantity_txt = new TextView(this);
            RelativeLayout.LayoutParams quantity_txtParams = new RelativeLayout.LayoutParams(50,50);
            quantity_txtParams.addRule(RelativeLayout.ALIGN_LEFT,title_txt.getId());
            quantity_txtParams.addRule(RelativeLayout.BELOW, title_txt.getId());
            quantity_txt.setId(54);
            quantity_txt.setLayoutParams(quantity_txtParams);
            quantity_txtParams.setMargins(10, 10, 0, 0);
            quantity_txt.setText("2");
 
 
            firstLayout.addView(quantity_txt);
            firstLayout.addView(title_txt);
            firstLayout.addView(price_txt);
            firstLayout.addView(imageView);
 
 
            relativeLayout.addView(firstLayout, firstLayoutParams);
		}
 
    }

Comment vous pouvez le voir le layout portant l'id na se positionne tout en haut, alors qu'il devrait se positionner en dessous du layout container_imge_product.

J'ai ensuite testé le même scénario en code, c'est à dire que j'ai crée le layout na en java et cette fois j'ai réussi à placer correctement mon layout na en dessous de container_imge_product.
Dois t-on créer tout le layout en dynamique ?