English 中文(简体)
和机器人 - 移动文本发行
原标题:Android - Moving text issue
  • 时间:2012-05-25 05:05:14
  •  标签:
  • android

我试图创建移动文本 。 我装箱了表面视图和环绕它的线条 。 但是它没有给我显示一个移动动作, 而是在“ 强”

但我需要的是把这一点移到 ** - & gt; ** 明白了吗?

这是我的代码

package com.CurvePackage.Curve;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;

public class Origin extends SurfaceView implements SurfaceHolder.Callback {
    Context context1;
    private MainThread thread;
    private int x=0;
    private int y=0;


    public Origin(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        setWillNotDraw(false);
        context1 = context;
        getHolder().addCallback(this);
        thread = new MainThread(getHolder(), this);

        setFocusable(true);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setTextSize(23);
        paint.setFakeBoldText(true);
        paint.setColor(Color.YELLOW);
        // int score=(10-sprites.size()*100);
        x=x+20;
        y=y+20;
        canvas.drawText("ewqewqe", x, y, paint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        return super.onTouchEvent(event);
        // Toast.makeText(getba, "Replay clicked!", Toast.LENGTH_SHORT).show();
    }

    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub

    }

    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        thread.setRunning(true);
        thread.start();

    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        thread.setRunning(false);
        // TODO Auto-generated method stub
//      boolean retry = true;
//      while (retry) {
//          try {
//              thread.join();
//              retry = false;
//          } catch (InterruptedException e) {
//              // try again shutting down the thread
//          }
//      }

    }
}

主线索

package com.CurvePackage.Curve;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class MainThread extends Thread {

    // flag to hold game state
    private boolean running;
    private SurfaceHolder surfaceHolder;
    private Origin origin;
     static final long FPS = 15;

    public void setRunning(boolean running) {
        this.running = running;
    }

    @Override
    public void run() {

        long ticksPS = 1000 / FPS;
        long startTime;
        long sleepTime;

        while (running) {
            Canvas c = null;
            startTime = System.currentTimeMillis();
            try {
                   c = origin.getHolder().lockCanvas();
                   synchronized (origin.getHolder()) {
                       origin.onDraw(c);
                   }
            } finally {
                   if (c != null) {
                       origin.getHolder().unlockCanvasAndPost(c);
                   }
            }


            sleepTime = ticksPS-(System.currentTimeMillis() - startTime);
            try {
                   if (sleepTime > 0)
                          sleep(sleepTime);
                   else
                          sleep(10);
            } catch (Exception e) {}
        }

    }

    public MainThread(SurfaceHolder surfaceHolder, Origin origin) {
        super();
        this.surfaceHolder = surfaceHolder;
        this.origin = origin;
    }

}
最佳回答

在你画文字之前,你需要用你的笔迹方法画出整个背景。

Paint p2 = new Paint();
p2.setStyle(Style.FILL);
canvas.drawRect(0, 0, screenWidth, screenHeight, p2);
//draw text here

这将从上次绘制画布时的文字上完全涂色, 并删除此拖曳效果 。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...