0

在这段代码中,我正在构建一个在运行时将相同图像多次添加到相对布局的方法。但是,调试时没有显示图像。添加的文本视图运行正常。有人可以解释如何使图像可见吗?提前致谢。

我的代码:

public class TestActivity extends Activity {
ArrayClass arraysObject1 = new ArrayClass();
ArrayList<ImageView> mImages = new ArrayList<ImageView>();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RelativeLayout layout = new RelativeLayout(this);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
        layout.setLayoutParams(params);
        layout.setBackgroundColor(Color.parseColor("#FFFFFF"));

        //textview is working
        TextView testText = new TextView(this);
        testText.setText("Alle aangeboden vacatures vindt u hieronder terug.");
        testText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    layout.addView(testText);


        RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        imgParams.addRule(RelativeLayout.CENTER_IN_PARENT);

        for(int i=0; i<arraysObject1.array1.size(); i++)
        {
            mImages.add(new ImageView(this));
            mImages.get(i).setVisibility(View.VISIBLE);
            mImages.get(i).setBackgroundResource(R.drawable.work);
            mImages.get(i).setLayoutParams(imgParams);

            layout.addView(mImages.get(i));

        }
        setContentView(layout);
    }
}
4

1 回答 1

0

你的循环for(int i=0; i < arraysObject1.array1.size(); i++)似乎没有被执行。 arraysObject1.array1是空的。

于 2012-12-02T14:18:44.690 回答