カスタムビューランプ
1378 ワード
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。 , 。