Android Banner AD Strip

Source: Internet
Author: User

Package com.example.ex_templete;


Import Android.content.Context;

Import Android.graphics.Canvas;

Import Android.graphics.Color;

Import Android.graphics.Paint;

Import Android.graphics.Paint.Style;

Import Android.util.AttributeSet;

Import Android.util.DisplayMetrics;

Import Android.view.Display;

Import Android.view.View;

Import Android.view.WindowManager;


public class Viewpagerindicator extends View {

private paint paint;

Private Paint Forepaint;

private float Foreoffset;

private static final int RADIUS = 10;

private static int pivot_x = 30;

private static final int pivot_y = 30;

private static final int LEN = 3 * RADIUS;

protected void OnDraw (canvas canvas) {

Super.ondraw (canvas);

int width = (7-1) * LEN + 2 * RADIUS;

int screenwidth = Getscreenwidth ();

pivot_x = (screenwidth-width)/2;

for (int i = 0; i < 7; i++) {

Canvas.drawcircle (pivot_x + i * 3 * radius, pivot_y, radius, paint);

}

Canvas.drawcircle (pivot_x + foreoffset, pivot_y, RADIUS, Forepaint);

}

Get the width of the screen

private int getscreenwidth () {

WindowManager windowmgr = (WindowManager)

GetContext (). Getsystemservice

(Context.window_service);

Display display = Windowmgr.getdefaultdisplay ();

Displaymetrics outmetrics = new Displaymetrics ();

Display.getmetrics (Outmetrics);

return outmetrics.widthpixels;

}


public void Updateoffset (int position, float positionoffset)

{

Foreoffset = position% 7 * LEN

+ Positionoffset * LEN;

Invalidate ();

}


Public Viewpagerindicator (context context, AttributeSet Attrs) {

Super (context, attrs);

Paint = new Paint (Paint.anti_alias_flag);

Paint.setcolor (color.red);

Paint.setstyle (Style.stroke);//Tight grades

Paint.setstrokewidth (1);//Crypto  argon harm

Forepaint = new Paint (Paint.anti_alias_flag);

Forepaint.setcolor (Color.Blue);

}

}


This article is from the "Android Development" blog, so be sure to keep this source http://9238253.blog.51cto.com/9228253/1536629

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.