使用linearlayouts创建表

时间:2011-09-30 21:12:37

标签: android android-linearlayout

我想创建一个包含行和列以及内部图像的表。返回该布局的方法是:

    public LinearLayout getLayout(int rows, int columns, Drawable img, Context ctx) {

    Bitmap bitmap = ((BitmapDrawable)img).getBitmap();
    Drawable d = new BitmapDrawable(resize(bitmap, 15, 15));

    LinearLayout.LayoutParams paramsCard = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    paramsCard.setMargins(5, 5, 5, 5);      

    LinearLayout.LayoutParams paramsRow = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    LinearLayout.LayoutParams paramsTable = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

    LinearLayout lyTable = new LinearLayout(ctx);
    lyTable.setLayoutParams(paramsTable);
    lyTable.setOrientation(LinearLayout.VERTICAL);

    for(int i = 0; i < rows; i++){          
        LinearLayout lyRow = new LinearLayout(ctx);
        lyRow.setOrientation(LinearLayout.HORIZONTAL);
        lyRow.setLayoutParams(paramsRow);
        for(int j = 0; j < columns; j++){
            View viewCard = new View(ctx);
            viewCard.setLayoutParams(paramsCard);
            viewCard.setBackgroundDrawable(d);
            lyRow.addView(viewCard);                
        }
        lyTable.addView(lyRow);
    }       
    return lyTable;
}

为什么我只能获得一张图片?

0 个答案:

没有答案