Shadow: shadows can be set for various shapes (rectangle, circle, etc.) and text.
What is the principle of shadow?
In fact, it is very simple. You need to set shadow things as a main layer. Then draw a shadow layer under the main layer.
Shadow creation involves an important function:
Public void setShadowLayer (float radius, float dx, float dy, int color)
Radius: Shadow radius
Dx: offset of the X axis
Dy: the offset in the Y axis.
Color: shadow color
Note: If the radius is set to 0, the shadow is removed.
Specific implementation: [java] package xiaosi. textShadow;
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. OS. Bundle;
Import android. view. View;
Public class TextShadowActivity extends Activity
{
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (new drawCanvas (this ));
}
Class drawCanvas extends View
{
Private Bitmap bitmap = null;
Public drawCanvas (Context context)
{
Super (context );
Bitmap = BitmapFactory. decodeResource (getResources (), R. drawable. I _skinprocess );
}
@ Override
Protected void onDraw (Canvas canvas)
{
Super. onDraw (canvas );
// Create a Paint object
Paint paint1 = new Paint ();
// Set the color
Paint1.setColor (0xFFFFFF00 );
// Set the shadow (Soft Edge, X axis displacement, Y axis displacement, and shadow color)
Paint1.setShadowLayer (5, 3, 3, 0xFFFF00FF );
// Solid rectangle & Its shadow
Canvas. drawText ("I love you", 20, 40, paint1 );
Paint paint2 = new Paint ();
Paint2.setColor (Color. GREEN );
Paint2.setShadowLayer (10, 5, 2, Color. YELLOW );
Canvas. drawText ("You are stupid", paint2 );
Paint paint3 = new Paint ();
Paint3.setColor (Color. RED );
Paint3.setShadowLayer (30, 5, 2, Color. GREEN );
Canvas. drawCircle (50,130, 30, paint3 );
Paint paint4 = new Paint ();
Paint4.setShadowLayer (5, 8, 7, Color. DKGRAY );
Canvas. drawBitmap (bitmap, 50,200, paint4 );
}
}
}
From agods-footprint