I wrote a class inherits VIew, realized onDraw method in onDraw method where I drew a straight line with the code,
Then it ends with the line of code drew two dots, I want to achieve such a function, like in between these two dots
Marquee achieve the effect, but also want to achieve the Marquee effect in the form of dots and dots are painted with their own code. May I ask how
Achieve ah. Great God help answer the request! ! ! !
Reply:
With TextView not on line yet, with the relative placement, draw a line, add a little text above run back and forth
Reply:
Define a dot position: position,
Define a Handler,
In onDraw () where, according to the position of the value of the circle points, unfinished one, send a delay of the Message, the receiver in the Message Handler inside, and increase the value of position, and then call invalidate (), will trigger calls onDraw (). This time onDraw () in the value of the position is already increasing, and that point of time you draw a circle, the visual is a little dot moving forward.
value of the delay of their own grasp, smaller, faster moving dots, bigger, slower moving dots
Reply:
I did not make it clear that the above is not the marquee effect, say to, for example, reported that the light rail station map, when it ran between two stations when the stops graph shows
That dot the rolling effect, a bright light first, then two lights, then three lights, is you want to achieve this effect, but also have my own dot painting. That is how to make switching from one point to several points between two points there.
Reply:
Sequentially switched my above question asked some questions, in fact, I do not want to implement a point Marquee in motion, I want to achieve the kind of results reported light rail station, is between two stations from one to four highlights highlights .
Reply:
Truth is the same,
For example, you draw a bright spot in the second, unfinished, sent a delay Message, then over one second, Handler received the Message, adjust the position, calling invalidate (), triggering calls onDraw (). Then, draw two highlights. After adjustment of the position is above.
After re-call onDraw (), is re-drawn again, and the second in onDraw () in painting things will be erased.
Therefore, the effect of the above is that the second bright point, the next second highlight two points, the next second highlight three points. . .
Reply:
do not know what your problem is solved yet, I have seen this example, you look ah
Reply:
package com.test;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
public class DrawActivity extends Activity {
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
MyView mv = new MyView (this);
setContentView (mv);
}
public class MyView extends View {
private int p;
MyView (final Context context) {
super (context);
new Thread (new Runnable () {
@ Override
public void run () {
/ / TODO Auto-generated method stub
while (true) {
if (p> 500) {
p = 0;
}
p + = 20;
try {
Thread.sleep (300);
} Catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
Activity a = (Activity) context;
a.runOnUiThread (new Runnable () {
@ Override
public void run () {
/ / TODO Auto-generated method stub
MyView.this.invalidate ();
}
});
}
}
.}) Start ();
}
@ Override
protected void onDraw (Canvas canvas) {
/ / TODO Auto-generated method stub
super.onDraw (canvas);
/ / First define a paint
Paint paint = new Paint ();
Solid rectangle
- / / Draw a rectangle area/ / Set the color
paint.setColor (Color.BLUE);
/ / Set the style - filled
paint.setStyle (Style.FILL);
/ / Draw a rectangle
canvas.drawRect (new Rect (0, 0, getWidth (), getHeight ()), paint);
/ / Draw a hollow rectangle
/ / Set the color
paint.setColor (Color.RED);
/ / Set the style - a hollow rectangle
paint.setStyle (Style.STROKE);
/ / Draw a rectangle
canvas.drawRect (new Rect (10, 10, 100, 30), paint);
/ / Emoji
/ / Set the color
paint.setColor (Color.GREEN);
/ / Emoji
canvas.drawText ("Hello", 10, 50, paint);
/ / Drawing
/ / Create a bitmap from a resource file
Bitmap bitmap = BitmapFactory.decodeResource (getResources (), R.drawable.icon);
/ / Drawing
canvas.drawBitmap (bitmap, 10 + p, 60, paint);
}
}
}
Reply:
package com.test;Or you want is this effect
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
public class DrawActivity extends Activity {
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
MyView mv = new MyView (this);
setContentView (mv);
}
public class MyView extends View {
private int p;
private int bw, bh;
private Rect r;
MyView (final Context context) {
super (context);
new Thread (new Runnable () {
@ Override
public void run () {
/ / TODO Auto-generated method stub
while (true) {
if (p> 500) {
p = 0;
}
p + = 60;
try {
Thread.sleep (300);
} Catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
Activity a = (Activity) context;
a.runOnUiThread (new Runnable () {
@ Override
public void run () {
/ / TODO Auto-generated method stub
MyView.this.invalidate (r);
}
});
}
}
.}) Start ();
}
@ Override
protected void onDraw (Canvas canvas) {
/ / TODO Auto-generated method stub
super.onDraw (canvas);
/ / First define a paint
Paint paint = new Paint ();
Solid rectangle
- / / Draw a rectangle area/ / Set the color
paint.setColor (Color.BLUE);
/ / Set the style - filled
paint.setStyle (Style.FILL);
/ / Draw a rectangle
canvas.drawRect (new Rect (0, 0, getWidth (), getHeight ()), paint);
/ / Draw a hollow rectangle
/ / Set the color
paint.setColor (Color.RED);
/ / Set the style - a hollow rectangle
paint.setStyle (Style.STROKE);
/ / Draw a rectangle
canvas.drawRect (new Rect (10, 10, 100, 30), paint);
/ / Emoji
/ / Set the color
paint.setColor (Color.GREEN);
/ / Emoji
canvas.drawText ("Hello", 10, 50, paint);
/ / Drawing
/ / Create a bitmap from a resource file
Bitmap bitmap = BitmapFactory.decodeResource (getResources (), R.drawable.icon);
/ / Drawing
bw = bitmap.getWidth ();
bh = bitmap.getHeight ();
r = new Rect (p + 60, 00, p + 60 + bw, 500);
canvas.drawBitmap (bitmap, p, 60, paint);
}
}
}
Reply:
Thank you very much! ! !
Reply:
Say good example to chant
Reply:
The above code is ah
No comments:
Post a Comment