When you add the view to your "main" layout, you're telling it to FILL_PARENT
in both directions:
((ViewGroup) phoneLayout).addView(view, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
If you add a view that fills an entire LinearLayout
, that's all you'll ever see. When you add another one, it's "off the edge" in one direction(depending on orientation
). If you're trying to add them vertically, change the height to WRAP_CONTENT
. For a horizontal layout, change the width.
You also might want to simplify your addView
call in general. It shouldn't be necessary to cast it to ViewGroup
, for one thing. You can also skip the LayoutParams
constructor completely and just pass a width and height directly to the parent with a simpler call. Something like this should work:
phoneLayout.addView(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT);
All in all, though, Raghunandan's comment is the best "answer". You should probably be using a ListView
for this, since it's exactly what it was designed for.