方法有多种,只讲一种
使用View.setLeft和View.setRight
对于wrap_content的View,要横向平移,setRight是必要的,否则View的宽度会被改变(right应设定left + View.getWidth())
以下是带跑马灯效果的平移
if (!scheduled) { translationTimer.schedule(new TimerTask() { private int left; @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { int width = tv.getWidth(); tv.setLeft(++left); tv.setRight(left + width); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); if (left > metrics.widthPixels) { left = -width; } } }); } }, 0, 10); scheduled = true; }