Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically adding imageViews onto a linear Layout

Tags:

android

I am a newbie in Android. I have a requirement where I have to add the imageViews dynamically onto a linear layout and then have to animate each image individually.

I am not aware of the way to add the imageViews dynamically onto a linear layout. Plz help me out.

Thanks

like image 744
Priety Avatar asked Sep 27 '12 07:09

Priety


People also ask

Is linear layout a Viewgroup?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

How do I change to linear layout?

Go to -> Edit File Templates option. Change the ${ROOT_TAG} to LinearLayout in both of these LayoutResourceFile. xml and LayoutResourceFile_vertical. xml and you will always get LinearLayout as parent for future.


1 Answers

You can add view dynamically like this.

LinearLayout.LayoutParams imParams = 
    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageView imSex = new ImageView(context);
imSex.setImageResource(getmyImage());

mainlayout.addView(imSex,imParams);
like image 90
RajaReddy PolamReddy Avatar answered Sep 28 '22 21:09

RajaReddy PolamReddy