canvas.drawLine(10, 10, 10, canvas.getHeight(), paint);
canvas.drawLine(0, canvas.getHeight(), 100, canvas.getHeight(), paint);
//the vertical line can see, but the level line disappear,at first I thought it's because the length ,so I minus 30 on length,but it's the same
canvas.drawLine(0, canvas.getHeight()-30, 100, canvas.getHeight()-30, paint);
我要在其中放置一张图片,但它不在屏幕范围内。视图是继承和覆盖onDraw
方法。我尝试过设置默认背景,高度也在屏幕之外。
有人可以帮助我吗?
答案 0 :(得分:1)
看起来你甚至没有检查canvas.getHeight()返回的内容。请检查它,你会知道为什么线不可见。 另请注意,画布大小可能比视图大。您应该使用View.getHeight()
答案 1 :(得分:0)
默认Canvas构造函数的初始目标密度为DENSITY_NONE,因此图层大小设置为0 - 0.您必须为canvas设置setDesity,或者从Display或此View.getHeight获取屏幕的getHeight 。通过这种方式,我理解它。