0

我在获取布局宽度时遇到问题...添加新视图后它没有返回实际宽度?...我该如何解决...谢谢...这是我的示例代码。

llDayHeaderTable = (LinearLayout) viewGroup
            .findViewById(R.id.llDayHeaderTable);
    LayoutInflater vi = (LayoutInflater) parent
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (View v : vTmp) {
        llDayHeaderTable.removeView(v);
    }
    vTmp.removeAllElements();

    for (int i = 0; i < dto.arrProductTitleList.size(); i++) {
        String productName = dto.arrProductTitleList.get(i).productInfoName;
        vItemHeader = vi.inflate(R.layout.layout_kpi_sku_group_accum_item,
                null);
        TextView tv = (TextView) vItemHeader
                .findViewById(R.id.tvHeaderProduct);
        tv.setText("" + productName);
        llDayHeaderTable.addView(vItemHeader);
        vTmp.add(vItemHeader);
    }
int width = llDayHeaderTable.getWidth();
4

1 回答 1

6

尝试使用 getMeasuredHeight() 和 getMeasuredWidth() 而不是 getWidth() 和 getHeight()

llDayHeaderTable.measure(0, 0);
final int w = llDayHeaderTable.getMeasuredWidth();
final int h = llDayHeaderTable.getMeasuredHeight();
于 2013-09-03T04:47:35.180 回答