标签:android private package import public
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);
}
// 得到屏幕的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);
}
}
本文出自 “android开发” 博客,请务必保留此出处http://9238253.blog.51cto.com/9228253/1536629
Android Banner 广告条,布布扣,bubuko.com
标签:android private package import public
原文地址:http://9238253.blog.51cto.com/9228253/1536629