以编程方式将线性布局添加到彼此之上

时间:2016-08-22 20:26:49

标签: android

我正在尝试在另一个下方创建多个线性布局层,但结果仅显示第一个线性布局,我认为其他线性布局位于彼此的右侧而不是堆叠在彼此之上。你能帮忙吗?

我的代码如下:

public void actionBrowse(){

    LinearLayout HolderLL = new LinearLayout(browseActivity);

    LinearLayout picLL1 = new LinearLayout(browseActivity);
    LinearLayout picLL2 = new LinearLayout(browseActivity);
    LinearLayout picLL3 = new LinearLayout(browseActivity);
    LinearLayout picLL4 = new LinearLayout(browseActivity);
    LinearLayout picLL5 = new LinearLayout(browseActivity);


    HolderLL.addView(picLL1);
    HolderLL.addView(picLL2);
    HolderLL.addView(picLL3);
    HolderLL.addView(picLL4);
    HolderLL.addView(picLL5);


    LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

    for(int i=0; i<State.getInstance().getDesignUnit().getAllSavedImages().size(); i++){

        if(i<4) {
            ArrayList<DesignUnitViewer> savedImages = State.getInstance().getDesignUnit().getAllSavedImages();
            DesignUnitViewer dv = savedImages.get(i);
            Bitmap bmp = dv.getBacking_store();
            ImageView newImage = new ImageView(browseActivity);
            newImage.setImageBitmap(bmp);

            picLL1.addView(newImage, imageParams);
        }

        else if (i>= 4 && i <8){
            ArrayList<DesignUnitViewer> savedImages = State.getInstance().getDesignUnit().getAllSavedImages();
            DesignUnitViewer dv = savedImages.get(i);
            Bitmap bmp = dv.getBacking_store();
            ImageView newImage = new ImageView(browseActivity);
            newImage.setImageBitmap(bmp);

            picLL2.addView(newImage, imageParams);

        }
        else if( i >=8 && i<12){
            ArrayList<DesignUnitViewer> savedImages = State.getInstance().getDesignUnit().getAllSavedImages();
            DesignUnitViewer dv = savedImages.get(i);
            Bitmap bmp = dv.getBacking_store();
            ImageView newImage = new ImageView(browseActivity);
            newImage.setImageBitmap(bmp);

            picLL3.addView(newImage, imageParams);
        }else if (i >= 12 && i<16) {
            ArrayList<DesignUnitViewer> savedImages = State.getInstance().getDesignUnit().getAllSavedImages();
            DesignUnitViewer dv = savedImages.get(i);
            Bitmap bmp = dv.getBacking_store();
            ImageView newImage = new ImageView(browseActivity);
            newImage.setImageBitmap(bmp);

            picLL4.addView(newImage, imageParams);
        }else if (i >=16 && i<20){
            ArrayList<DesignUnitViewer> savedImages = State.getInstance().getDesignUnit().getAllSavedImages();
            DesignUnitViewer dv = savedImages.get(i);
            Bitmap bmp = dv.getBacking_store();
            ImageView newImage = new ImageView(browseActivity);
            newImage.setImageBitmap(bmp);

            picLL5.addView(newImage, imageParams);
        }

    }
    browseActivity.setContentView(HolderLL);
}

0 个答案:

没有答案