【发布时间】:2016-07-25 22:34:58
【问题描述】:
我正在尝试将卡片视图绘制到 pdf 的画布上。不幸的是,没有绘制卡片视图。但是绘制了一些测试文本。为什么我的汽车视图没有绘制?
代码:
// start a page
PdfDocument.Page page = document.startPage(pageInfo);
Canvas c = page.getCanvas();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1000, 50);
CardView card = new CardView(this);
card.setLayoutParams(params);
card.setRadius(4f);
Bitmap cardBitmap = Utils.loadBitmapFromView(card);
c.drawText("tessssssttt", 30, 30, p);
c.drawBitmap(cardBitmap, new Rect(0,0,1000,50), new Rect(5, 50, 995, 100), p);
document.finishPage(page);
查看到位图:
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap(v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
v.draw(c);
return b;
}
【问题讨论】:
-
我发现
CardView被绘制到位图,但没有绘制阴影,所以你认为CardView没有被绘制。有同样的问题:stackoverflow.com/questions/32931652/… -
@nshmura 我也读过它并将背景设置为黑色。还是什么都看不到。
标签: android android-canvas android-view