成都创新互联网站制作重庆分公司

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://cxhlcq.com/article/gpehei.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部