Remplir des ImageView dans un layout puis convertir ce layout
Bonjour à tous,
voici ce que j'essaie de faire:
le relativeLayout multi_image.xml:
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 25 26 27 28 29 30 31 32 33 34 35
| <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id ="@+id/images">
<ImageView
android:id="@+id/image1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/autre" />
<ImageView
android:id="@+id/image2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignTop="@+id/imageView1"
android:layout_alignLeft="@+id/imageView1"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:src="@drawable/add" />
<ImageView
android:id="@+id/image3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignTop="@+id/imageView2"
android:layout_alignLeft="@+id/imageView2"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:src="@drawable/add" />
</RelativeLayout> |
mon activité qui n'est pas créee dans ce xml:
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 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
|
//.....
//je suis ici dans une activité quelquonque
// je définie le layout comme ceci qui n'est pas celui de mon activité:
RelativeLayout layout;
layout=(RelativeLayout)findViewById(R.id.images);
// je remplie les ImageView de mon layout avec la méthode setViewInLayout()
setViewInLayout();
// je récupère le bitmap issue de la méthode convertToBitmap()
bitmapAUtiliser = convertToBitmap(layout);
// j'utilise le bitmapAUtiliser dans la suite du code...
//......
public void setViewInLayout(){
Bitmap b;
RelativeLayout layout;
layout=(RelativeLayout)findViewById(R.id.images);
ArrayList <Bitmap> bitmaps = new ArrayList <Bitmap>();
// je pense que le probleme est la...je n'arrive pas définir les ImageView image1,2,3 dans RelativeLayout Layout
ImageView image1 = (ImageView) findViewById(R.id.image1);
ImageView image2 = (ImageView) findViewById(R.id.image2);
ImageView image3 = (ImageView) findViewById(R.id.image3);
View v;
//ici je récupère les trois premiers bitmaps dans une ArrayList d'items(gridArray) et je remplie une ArrayList de de bitmaps
int count = 0;
for (int i=0;i<gridArray.size()-1;i++){
if (gridArray.get(i).getCheck()){
b = gridArray.get(i).getBitmap(getBaseContext());
bitmaps.add(b);
count++;
if (count==3){
break;
}
}
}
//ici je voudrais donc mettre les bitmaps dans les imageViews du fameux layout
int c = 0;
for (Bitmap subView : bitmaps){
switch (c){
case 0:
image1.setImageBitmap(subView);
c++;
break;
case 1:
image2.setImageBitmap(subView);
c++;
break;
case 2:
image3.setImageBitmap(subView);
break;
}
}
}
public Bitmap convertToBitmap(RelativeLayout layout) {
Bitmap bmap;
layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache();
bmap=layout.getDrawingCache();
return bmap;
} |
Donc je ne trouve pas le code qui me permet de définir image 1,2,3 par rapport au xml et/ou au layout??...et evidement j'ai un beau nullpointexception
Si bien sure je rajoute //setContentView(R.layout.multi_image) dans ma methode setViewInLayout ca fonctionne...mais ca n'est pas ce que je veux.
merci pour votre aide.