Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
rec.set(0, 0, canvas.getWidth(), canvas.getHeight()/2);
它按预期创建矩形,我知道 0, 0 是 x, y 但是我如何将 y 设置为底部,以便它在所有不同尺寸的设备上保持在底部?
你没有提供太多信息,所以我会陈述我的假设
x,y 将是形状的左上角,因此假设画布是设备的全高:
x - 0,因为您希望形状从左边缘开始,y - 设备的高度减去形状的高度
你的代码是
int width = canvas.getWidth(); int height = canvas.getHeight()/2; int x = 0; int y = canvas.getHeight() - height; rec.set(x, y, width, height);