如何将Runtime ImageViews添加到linearlayout中

时间:2013-05-09 12:56:51

标签: android

我正在获取运行时图像视图,如何将该图像视图添加到单个线性布局中。

LinearLayout linearLayout=new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams vp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    ImageView imageView= new ImageView(this);
    imageView.setImageBitmap(bitMap);
    imageView.setVisibility(View.VISIBLE);
    imageView.setBackgroundColor(0xFFFF00FF);

    //linearLayout=LinearLayout+imageView;
    LinearLayout.LayoutParams Iv=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(Iv);

    linearLayout.addView(imageView);
    setContentView(linearLayout,vp);

1 个答案:

答案 0 :(得分:0)

LinearLayout linearLayout=new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams vp=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

ImageView imSex = new ImageView(context);
addView(imSex,linearLayout);