2012-04-13 41 views
0

我得到的运行时动态imagebutton显示,但我有一些事情是显示在屏幕上之前,所以现在当我添加我的运行时图像按钮它将重叠前面的静态显示,我想添加运行时通过xml来的静态布局之后的imagebutton。请帮忙。管理布局运行时android

 for (int i =0;i<adapt_objmenu.image_array.length;i++){ 
     ImageButton b1 = new ImageButton(myrefmenu); 
      b1.setId(100 + i); 
      b1.setImageResource(R.drawable.bullet_1); 
     // b1.setPadding(left, top, right, bottom) 
      b1.setPadding(0, 10, 0, 10); 

      b1.setBackgroundColor(R.drawable.bg_navitionbar); 




      // b1.setText(adapt_objmenu.city_name_array[i]); 
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
      if (i > 0) { 
       lp.addRule(RelativeLayout.RIGHT_OF, b1.getId() - 1); 
      } 
      b1.setLayoutParams(lp); 
      relative.addView(b1); 

    //relate.addView(b1, i, new RelativeLayout.LayoutParams(width,height)); 

    //height = height+80; 



    } 

回答

0

如何将ImageButton添加到布局中?

如果您使用的LinearLayout作为主要的布局则不会发生这种情况?

LinearLayout layout = (LinearLayout)findViewById(R.id.myWrapperLayout); 
ImageButton imgBtn = new ImageButton(R.id.imgBtn); 
     imgBtn.setText("MyImageButton"); 
     layout.addView(imgBtn); 
+0

我使用的是同样的事情\ – Ved 2012-04-13 12:37:32

+0

什么是你的LinearLayout的方向是什么? – 2012-04-13 12:40:48

+0

看到我编辑了代码 – Ved 2012-04-13 12:44:50