Saturday, March 29, 2014

Background not full


New application:
Target SDK: API17: Adndroid4.2
Compile With: API18: Android4.3
Theme: Holo Light with Dark Actior Bar

Set up a 320 * 480 chart for the background in the code, in drawable-mdpi directory.


The same code with the picture, after running in full-screen display properly with the code works in the book.
I built a project where it is not full-screen on the right side is below the black, 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 unable to find the reason.
First, be sure not code thing.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Code impress with screenshots look
Reply:


 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));
}




}


  
package = "com.example.zbgtest"
android: versionCode = "1"
android: versionName = "1.0">

android: minSdkVersion = "8"
android: targetSdkVersion = "17" />

android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ android: style / Theme.NoTitleBar.Fullscreen"
>
android: name = "com.example.zbgtest.MainActivity"
android: label = "@ string / app_name">











Reply:
If you simulator resolution is 320 * 480, should not have a black border.
If other resolutions, the background image will be proportionally enlarged or reduced, but not tensile deformation, so that may have black edges.
After you use the estimated 480 * 800 resolution, image scaling, etc., will be black bars at the bottom.
Reply:
I also tried on his android phone, and use my own code there will be a black border, and replaced the book comes with a code that is full-screen,
The picture is the same ah ~
Also I put the above code into the code works in the book, but also full-screen.
You can run my own project is to have a black border ...
Reply:
My eclipse, step ADT New Project screenshot:





Help us to see.
Reply:
Oh, dpi problem. One picture shows a different dpi resolution on the same phone is not the same effect. You put the picture on the next hdpi directory try.
Reply:


Reply:
drawable-ldpi, mdpi, hdpi have tried,
Ldpi placed below the display screen will be exceeded.
Hdpi placed below the display is smaller than with the above display.
On mdpi Here is the above effect.
Reply:
reference to the 8th floor zlgkaixin68 reply:
drawable-ldpi, mdpi, hdpi have tried,
Ldpi placed below the display screen will be exceeded.
Hdpi placed below the display is smaller than with the above display.
On mdpi Here is the above effect.

Reply:
canvas.drawBitmap (bmpBg, 0, 0, paint);
==>
canvas.drawBitmap (bmpBg, null, new RectF (0, 0, w, h), paint);
Reply:
10th Floor, Thanks so much, has full screen.
Reply:
Also, anyone know the reason for the above problem is?

No comments:

Post a Comment