I use canvas.drawText on a SurfaceView and the output looks correct on the emulator but when I deploy the app to my device (a Samsung Galaxy S3) the text is written from top to bottom like this:
T
E
s
t
It looks like a line-break is added after each character of the text.
It doesn't matter if the device is landscape or not, it just never works and I can't figure out why.
What am I doing wrong?
In AndroidManifest.xml I use:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
The code I'm using:
public class MainActivity extends Activity {
DemoView renderView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
renderView = new DemoView(this);
setContentView(renderView);
}
@Override
public void onResume() {
super.onResume();
renderView.resume();
}
@Override
public void onPause() {
super.onPause();
renderView.pause();
}
private class DemoView extends SurfaceView implements Runnable{
Thread renderThread = null;
SurfaceHolder holder;
volatile boolean running = false;
public DemoView(Context context){
super(context);
this.holder = getHolder();
}
public void resume() {
running = true;
renderThread = new Thread(this);
renderThread.start();
}
public void run() {
Canvas canvas;
while(running) {
if(!holder.getSurface().isValid())
continue;
Paint test = new Paint(Color.YELLOW);
test.setColor(Color.YELLOW);
canvas = holder.lockCanvas();
canvas.drawText("TEst", 10, 10, test);
holder.unlockCanvasAndPost(canvas);
}
}
public void pause() {
running = false;
while(true) {
try {
renderThread.join();
break;
} catch (InterruptedException e) { // retry
}
}
}
}
}
Thanks for your help! Stephoid