Target SDK: API17: Adndroid4.2
Compile With: API18: Android4.3
Theme: Holo Light with Dark Actior Bar
in the code set a 320 * 480 map as the background , on the drawable-mdpi directory.
same code with the picture in the book project with code to run after full normal display.
I built a project where it is not full-screen on the right is below a black border , not full screen.
personal feeling is that a relationship with the SDK version . My adt version is 20130729 . Downloaded from the official website :
adt-bundle-windows-x86-20130729.
get a long time, been able to find the reasons .
First, be sure not the code thing.
------ Solution ---------------------------------------- ----
canvas.drawBitmap (bmpBg, 0, 0, paint);
==>
canvas.drawBitmap (bmpBg, null, new RectF (0, 0, w, h), paint);
----- - eference ---------------------------------------
code with the view put screenshot look
------ eference ---------------------------------------
package com.example.zbgtest;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
public class mySur extends SurfaceView implements Callback{
private Canvas canvas;
private Paint paint;
private SurfaceHolder holder;
private boolean flag;
private Bitmap bmpBg;
private MyThread th_draw;
public mySur(Context context) {
super(context);
// TODO Auto-generated constructor stub
flag = true;
holder = getHolder();
holder.addCallback(this);
paint = new Paint();
paint.setColor(Color.WHITE);
bmpBg = BitmapFactory.decodeResource(this.getResources(), R.drawable.menu);
}
public void logic(){
}
public void reallyDraw(){
canvas.drawBitmap(bmpBg, 0, 0, paint);
}
public void draw(){
try{
canvas = holder.lockCanvas();
if(canvas != null){
reallyDraw();
}
}catch(Exception e){
}finally{
if(canvas != null){
holder.unlockCanvasAndPost(canvas);
}
}
}
class MyThread extends Thread{
private int time;
public MyThread(int time){
this.time = time;
}
@Override
public void run(){
while(flag){
try {
draw();
logic();
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
th_draw = new MyThread(50);
th_draw.start();
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
flag = false;
}
}
package com.example.zbgtest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new mySur(this));
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zbgtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>
<activity
android:name="com.example.zbgtest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
------ eference ------------------------------------ ---
If you simulator resolution is 320 * 480 , it should be no black edges .
If other resolutions , the background map will proportionally enlarged or reduced , but without stretching , so that may have black edges .
estimated that you are using a 480 * 800 resolution , pictures, etc. After scaling , black bars will appear at the bottom .
------ eference --------------------------------------- < br> I also own android phone tried, with my own code will have black bars , and replaced with code that comes with the book is full screen ,
picture is the same one ah ~
Also I put the above code into the code works in the book , but also the full screen .
can run my own works is a black border ...
------ eference ----------------------- ----------------
my eclipse, ADT new project step screenshot:
help us to see .
------ eference --------------------------------------- < br> Oh , dpi issue. A different picture in the same dpi resolution display on the phone is not the same . You put the picture on the hdpi directory try.
------ eference --------------------------------------- < br>
------ eference ------------------------------------ ---
drawable-ldpi, mdpi, hdpi have tried,
on ldpi below shows the effect will be beyond the screen .
placed hdpi Now, with the above shown smaller than the display .
placed mdpi Below, is the above effect.
------ eference --------------------------------------- < br>
------ eference ---------------------------------------
10 floor , too thanks , already full .
------ eference - --------------------------------------
Also , who knows the reasons for the above problem where is it ?
没有评论:
发表评论