The Shadow of Android programming (Shadow) Making method _android

Source: Internet
Author: User
Tags drawtext

This article illustrates the shadow (Shadow) method of Android programming. Share to everyone for your reference, specific as follows:

First look at the operating effect of the chart is as follows:

Shadow making: Includes various shapes (rectangles, circles, etc.), as well as text, and so on can set shadows.

What is the principle of shadow making?

In fact it is very simple that you need to set the shadow of something that is considered a primary layer. Then draw a shadow layer underneath the main layer.

Shadow making involves an important function:

public void Setshadowlayer (float radius, float dx, float dy, int color)

Parameters:

Radius: Shadow Radius

Offset of dx:x axis direction

Offset of dy:y axis direction

Color: Shadow Colors

Note: If the radius is set to 0, the meaning is to remove the shadow.

Specific implementation:

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) {s
    Uper.oncreate (savedinstancestate);
  Setcontentview (This) (new Drawcanvas);
    Class Drawcanvas extends View {private Bitmap Bitmap = null;
      Public Drawcanvas {Super (context);
    Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.i_skinprocess);
      } @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas);
      Establish Paint object Paint paint1 = new Paint ();
      Set color Paint1.setcolor (0XFFFFFF00); Set Shadow (soft edge, X-axis displacement, Y-axis displacement, shadow color) Paint1.setshadowlayer (5,3, 3, 0XFFFF00FF);
      Filled Rectangle & its shadow Canvas.drawtext ("I love you very much", 20,40,paint1);
      Paint Paint2 = new Paint ();
      Paint2.setcolor (Color.green);
      Paint2.setshadowlayer (5, 2, color.yellow);
      Canvas.drawtext ("You are so silly", 20,60,paint2);
      Paint Paint3 = new Paint ();
      Paint3.setcolor (color.red);
      Paint3.setshadowlayer (5, 2, color.green);
      Canvas.drawcircle (M, 130,30, Paint3);
      Paint paint4 = new Paint ();
      Paint4.setshadowlayer (5, 8, 7, Color.dkgray);
    Canvas.drawbitmap (bitmap, MB, paint4);

 }
  }
}

For more information on Android-related content readers can view the site: "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.