管理布局运行时android

时间:2012-04-13 12:29:57

标签: android android-layout

我正在显示运行时动态图像按钮,但我之前有一些显示在屏幕上的东西,所以现在当我添加我的运行时图像按钮时,它将重叠前一个静态显示,我想在静态之后添加运行时图像按钮通过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;



    }

1 个答案:

答案 0 :(得分:0)

如何将ImageButton添加到布局?

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

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