0

I am trying to dynamically creating imageview but it is not visible my code is:

RelativeLayout layout = (RelativeLayout)findViewById(R.id.MultiQuesRelaLayOut);

final ImageView[] im=new ImageView[10];
for(int img=0; img<2.length; img++)
{
    im[img]=new ImageView(this);   
    RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams
         ((int)LayoutParams.WRAP_CONTENT,(int)LayoutParams.WRAP_CONTENT);
    params.leftMargin=25;
    params.topMargin=(img+1)*(35+add);
    im[img].setId(img);
    im[img].layout(5,5,5,5);
    im[img].setVisibility(View.VISIBLE);
    im[img].setBackgroundColor(color.background_dark);
    im[img].setPadding(5, 15, 5, 15);
    im[img].setLayoutParams(params);
    layout.addView(im[img]);
    im[img].setOnClickListener(ImageOnClick(im[img]));
}

How to view imageview on form by changnig it s background image or some thing like that ?

Hopes for your suggestion

Thanks

Flat Eric
  • 7,971
  • 9
  • 36
  • 45
user3664724
  • 425
  • 1
  • 6
  • 18

1 Answers1

1

You have created the ImageView with this LayoutParams: wrap_content, wrap_content, but you have not add img to the ImageView, so, the content length is 0 for height and width.

Mou
  • 2,027
  • 1
  • 18
  • 29
  • how to add height and width for creating dynamic imageview – user3664724 Dec 13 '14 at 10:54
  • With wrap_content, the imageview set height and width when you add a img (take the dimensions from image). You can set a fixed width and height creating layout params with fixed positive numbers: params= new RelativeLayout.LayoutParams(100, 100); - in pixels- – Mou Dec 13 '14 at 10:59
  • Mou by putting 100,100 on my random click it open gallery but cant see imageview can i change imageview background to see it – user3664724 Dec 13 '14 at 11:05
  • http://stackoverflow.com/questions/19461191/how-to-set-backgroundcolor-on-imageview-on-android – Mou Dec 13 '14 at 11:07