java - Programmatically Adding ImageViews to RelativeLayout -


i creating 2 column list of images in form of imageviews, contained in relativelayout. here diagram of looks like:

img

the relativelayout has been created xml file id of "@id/cardlist";

<scrollview     android:layout_width="220dp"     android:layout_height="350dp"     android:id="@+id/cardlistscroll"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:fillviewport="true">     <relativelayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/cardlist">     </relativelayout> </scrollview> 

the imageviews being created within java class , should continue created until there no more images in typedarray set in while loop.

typedarray images = getresources().obtaintypedarray(r.array.cardimages);     relativelayout cardlist = (relativelayout) findviewbyid(r.id.cardlist);      int counter = 1;     int length = images.length();     imageview[] cards = new imageview[3];      relativelayout.layoutparams cardaparams = new relativelayout.layoutparams(215, 215);     relativelayout.layoutparams cardbparams = new relativelayout.layoutparams(215,215);      while (counter < length) {         cards[counter] = new imageview(this);         if (counter % 2 != 0) {             cardaparams.setmargins(0,((counter-1)/2)*225,0,0);             cards[counter].setlayoutparams(cardaparams);             cards[counter].setimageresource(images.getresourceid(counter-1, 0));             cardlist.addview(cards[counter]);             toast.maketext(create.this, ""+counter, toast.length_short).show();             counter++;         } else {             cardbparams.setmargins(225,((counter-2)/2)*225,0,0);             cards[counter].setlayoutparams(cardbparams);             cards[counter].setimageresource(images.getresourceid(counter-1, 0));             cardlist.addview(cards[counter]);             toast.maketext(create.this, ""+counter, toast.length_short).show();             counter++;         }     }     images.recycle(); 

i have been able create 2 of images within list, no more that, meaning can create 1 row, when want multiple. (i tested change "while(counter < 3){" "while(counter <= 3)".

my presumption each new imageview in cards[] array need corresponding relativelayout.layoutparams. experimented in creating array of relativelayout.layoutparams cardsparams[] not able work.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -