网站建设资讯

NEWS

网站建设资讯

AndroidBanner广告条

package com.example.ex_templete;

创新互联自2013年起,是专业互联网技术服务公司,拥有项目网站建设、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元德保做网站,已为上家服务,为德保各地企业和个人服务,联系电话:18980820575

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);

}

//得到屏幕的Width

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);// 绌哄績

paint.setStrokeWidth(1);// 杈圭殑鍘氬害

forePaint = new Paint(Paint.ANTI_ALIAS_FLAG);

forePaint.setColor(Color.BLUE);

}

}


分享题目:AndroidBanner广告条
网址分享:http://cdweb.net/article/gpehei.html