我正在尝试将一个ShapeDrawable对象放入一个TableLayout单元格中。按照文档here的建议,我创建了一个自定义视图mCustomView,然后通过执行以下操作将视图添加到TableLayout中
mRow.addView(mCustomView)
mTableLayout.addView(mRow)一切运行正常,没有错误,但形状根本不显示。
创建可绘制的代码是
icon = new ShapeDrawable(new ArcShape(0, 360));
icon.setBounds(0, 0, 20, 20);
icon.getPaint().setColor(parseColor);发布于 2011-05-16 19:46:22
经过进一步的挖掘和研究,最好的solution是将ShapeDrawable对象传递给ImageView构造函数,然后将该视图添加到表行中,如下所示
ShapeDrawable icon = new ShapeDrawable(new ArcShape(0, 360));
icon.getPaint().setColor(parseColor);
icon.setIntrinsicHeight(30);
icon.setIntrinsicWidth(30);
ImageView iv = new ImageView(this);
iv.setImageDrawable(icon);
mRow.addView(iv);
mTableLayout.addView(mRow)此解决方案还具有摆脱自定义View类的优势。
https://stackoverflow.com/questions/6011827
复制相似问题