Positionnement dynamique dans un relative layout
Bonjour,
Je souhaite positionner un objet à gauche d'un ImageView. En xml, il n'y apas de problème, j'utilise le code suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<RelativeLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
<ImageView
android:id="@+id/bulle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:adjustViewBounds="true"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:src="@drawable/bullet11" />
<ImageView
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/bulle"
android:adjustViewBounds="true"
android:maxWidth="320dp"
android:src="@drawable/left" />
</RelativeLayout> |
Mon problème est qu'en réalité, le composant que je dois afficher est un descendant de View que j'ai créé pour afficher des gifs animées.
Je dois donc l'instancier dynamiquement et surtout le positionner dynamiquement.
J'utilise le code suivant:
Code:
1 2 3 4 5 6 7 8
|
RelativeLayout emplacement=( RelativeLayout ) findViewById(R.id.main );
MyGifView animation=new MyGifView(this.getBaseContext(),R.drawable.gifanim);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0,0, 0,0);
animation.setLayoutParams(params);
setContentView(animation, params); |
mais je n'obtiens pas le résultat escompté, l'image occupe tout l'écran. Je n'ai pas trouvé d'équivalent à "android:layout_toLeftOf" dans les classes LayoutParams et View.
Quelqu'un pourrait-il m'aider? Pour info, je cible android 4.0