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 :
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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 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) { if (changed) { delayed.layout(l, t, r, b); information.layout(l + 10, t, r, b); } } }
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
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>
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>
Ce code provoque une boucle infinie sur onLayout et je ne vois pas bien pourquoi.
D'autre part, si je ne mets qu'un seul layout, je n'ai pas de boucle infinie mais rien ne s'affiche.
J'ai par ailleurs réalisée un version qui implémente onMeasure avec des valeurs constantes, mais sans aucune différence au
niveau du résultat.
Pourquoi ce comportement ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(200, 200); }
Que dois-je changer ?
Merci
Henri
Partager