public class MyText extends View implements Runnable { Paint mpaint=new Paint(); private String str=""; private String text=""; private int pointx,pointy=20; int textWidth; private boolean isover=false; public boolean isnetwrong=false; private Handler handler; public MyText(Context context,AttributeSet attrs) { super(context, attrs); mpaint.setColor(Color.WHITE); mpaint.setAntiAlias(true); mpaint.setStyle(Style.STROKE); mpaint.setTextSize(20); System.out.println("width===="+this.getWidth()); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); canvas.drawText(str,pointx,pointy,mpaint); } public void setStr(String string) { str=string; isover=false; textWidth = (int) mpaint.measureText(str); pointx=480; post(this); } public void setHandler(Handler hand) { handler=hand; } @Override public void run() { // TODO Auto-generated method stub if(isnetwrong) { //str="網路異常,請檢查網路設定!"; pointx=120; this.invalidate(); return; } pointx-=2; if(isover) { return; } if(pointx<=-(textWidth+240)) { isover=true; handler.sendEmptyMessage(LauncherActivity.TXT_SCROLL_OVER); } this.invalidate(); postDelayed(this, 20); } } 思路:自定義view,設置一字符串,而後在線程一直刷新並更改文字的起始位置,便可成爲跑馬燈效果,中止時設置isover爲true。用單個的跑馬燈效果還行,一個界面用多個有待測試。