Android打造不一样的新手引导页面(一)

本文详细介绍了如何在Android中创建一个独特的新手引导页面,重点在于自定义CirclePageIndicator组件的实现过程,包括构造方法的初始化、尺寸测量、绑定ViewPager、处理滑动事件以及在onDraw方法中绘制小圆点的逻辑。通过这种方式,可以实现更具个性化的用户引导体验。
摘要由CSDN通过智能技术生成

mCirclePageIndicator.setFillColor(0xFF888888);

// 设置外边框的颜色

mCirclePageIndicator.setStrokeColor(0xFF000000);

//设置外表框的宽度

mCirclePageIndicator.setStrokeWidth(2 * density);

2)下面我们一起来看我们是怎样CircleIndicator是怎样实现的


大概可以分为以下几个步骤

  • (1)继承View,在构造方法里面做一些初始化工作,包括初始化我们的自定义属性及画笔等

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

if (isInEditMode()) return;

//初始化自定义属性

final Resources res = getResources();

final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);

final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);

final int defaultOrientation = res.getInteger(R.integer

.default_circle_indicator_orientation);

在这里省略了若干方法

a.recycle();

final ViewConfiguration configuration = ViewConfiguration.get(context);

mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);

}

  • (2) 在我们的onMeasure方法里面根据方向的不同测量我们的大小

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

if (mOrientation == HORIZONTAL) {

setMeasuredDimension(measureLong(widthMeasureSpec), measureShort(heightMeasureSpec));

} else {

setMeasuredDimension(measureShort(widthMeasureSpec), measureLong(heightMeasureSpec));

}

}

/**

  • Determines the width of this view

  • @param measureSpec A measureSpec packed into an int

  • @return The width of the view, honoring constraints from measureSpec

*/

private int measureLong(int measureSpec) {

int result;

int specMode = MeasureSpec.getMode(measureSpec);

int specSize = MeasureSpec.getSize(measureSpec);

if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) {

//We were told how big to be

result = specSize;

} else {

//Calculate the width according the views count

  • 24
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值