Bonjour

Je désire superposer et décaler deux layouts dans un viewGroup. En me basant sur la doc
http://developer.android.com/referen...ViewGroup.html , j'ai fait l'implémentation basique suivante :


MainActivity.java:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
public class MainActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ItemView view = new ItemView(this);
        setContentView(view);
    }
}
ItemView.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
 
public class ItemView extends ViewGroup {
    View delayed;
    View information;
 
    public ItemView(Context context) {
        super(context);
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        delayed = layoutInflater.inflate(R.layout.delayed_layout, this, true);
        information = layoutInflater.inflate(R.layout.information_layout, this, true);
    }
 
    /**
     * Any layout manager that doesn't scroll will want this.
     */
    @Override
    public boolean shouldDelayChildPressedState() {
        return false;
    }
 
   @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View childAt = getChildAt(i);
            childAt.layout(l + i * 50, t, r, b);
        }
    }
}
delayed_layout.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:weightSum="1">
 
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="cancel"
        android:id="@+id/button"/>
</LinearLayout>
information_layout.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the information layout"
        android:id="@+id/textView"/>
</LinearLayout>
Avec ceci, rien ne s'affiche dans l'activité.
Qu'ai je oublié ?

Merci
Henri