我正在做应用程序,它在画布内显示一个图像。它在一个设备上运行良好,但是如果我在另一个设备上运行相同的应用程序,图像显示不正确,因为在此onDraw
我没有提及imageview宽度或高度,所以任何人都可以建议我如何给宽度和高于imageview在方onDraw
方法。如何使用画布显示图像的所有尺寸
我的代码是:
@Override
public void onDraw(Canvas canvas) {
Paint painto = new Paint();
painto.setAntiAlias(true);
painto.setColor(getResources().getColor(R.color.magnata));
painto.setStrokeWidth(3);
painto.setStyle(Paint.Style.FILL);
Paint paint = new Paint();
int leftx2 = (int) (10 * (screenWidth/1024));
int topy1 = (int) (10 * (screenHeight/600));
Bitmap kangoo = BitmapFactory.decodeResource(getResources(),
R.drawable.kangoo);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(kangoo, leftx2, topy1, painto);
}
ok.but我的代码我在这里使用kangoo图像我没有提到任何hight和宽度先前.so如果给内部onsizechange()new宽度和高度也没有使用权利? – user1105975
尝试使用newwidth和newheight而不是screenWidth和screenHeight – Abx
是的。屏幕宽度和screenhight是在这个设备我可以运行该设备的高度和宽度 – user1105975