温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android Banner 广告条

发布时间:2020-07-10 10:06:40 来源:网络 阅读:774 作者:风清扬lfg 栏目:移动开发

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

}

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI