【发布时间】:2015-03-14 01:47:49
【问题描述】:
当我为扩展SurfaceView的类添加背景大尺寸位图时,它不适合屏幕并且一半消失了:
公共类背景{
Bitmap backBitmap;
int screenWidth;
int x;
int y;
AapView appview;
public BackGround(Bitmap bitmap, int screen_w, Aapview aapV){
this.backBitmap = bitmap;
this.screenWidth = screen_w;
this.x = 0;
this.y = 0;
aapview = aapV;
}
public void draw(Canvas canvas){
if(canvas != null){
canvas.drawBitmap(backBitmap, x, y, null);
}
}
}
public AapView(Context context, Mainapp app, int screen_width, int screen_height) { 超级(上下文);
background = new BackGround(BitmapFactory.decodeResource(getResources(), R.drawable.back_img), screen_width, this);
}
如何使背景位图适合屏幕?
【问题讨论】:
-
你是如何确定屏幕宽度的?度量单位是 dp 还是 px?就个人而言,我也会将位图放在 assets 文件夹中,以确保没有看不见的自动缩放问题。