0

我正在显示运行时动态图像按钮,但是我之前在屏幕上显示了一些东西,所以现在当我添加我的运行时图像按钮时,它将与以前的静态显示重叠,我想在出现的静态布局之后添加运行时图像按钮通过xml。请帮忙。

        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;



    }
4

1 回答 1

0

您如何将 ImageButton 添加到布局中?

如果您使用 LinearLayout 作为主要布局,那么这不会发生......

LinearLayout layout = (LinearLayout)findViewById(R.id.myWrapperLayout);
 ImageButton imgBtn = new ImageButton(R.id.imgBtn); 
        imgBtn.setText("MyImageButton"); 
        layout.addView(imgBtn);
于 2012-04-13T12:36:06.120 回答