Android 页面选择小圆点(页面显示自定义控件)

本文介绍了一种自定义Android页面指示器的方法,通过创建Dot和DoTView小圆点容器等组件,详细阐述了如何在布局文件中实现和应用这些自定义控件,提供了一个完整的示例项目,包括MainActivity和对应的XML布局文件,读者可以在GitHub上下载Demo进行实践。
摘要由CSDN通过智能技术生成

作用:自定义小控件

效果图:

style文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AbSlidingButtonStyle">
    <attr name="btn_bottom" format="integer|reference" />
    <attr name="btn_frame" format="integer|reference" />
    <attr name="btn_mask" format="integer|reference" />
    <attr name="btn_unpressed" format="integer|reference" />
    <attr name="btn_pressed" format="integer|reference" />
</declare-styleable>

<declare-styleable name="BaseDoT">
    <attr name="circleColor" format="color|reference" />
</declare-styleable>

<declare-styleable name="BaseDoTView">
    <attr name="slideCount" format="integer|reference" />
    <attr name="selectPosition" format="integer|reference" />
    <attr name="selectedIndicatorColor" format="color|reference" />
    <attr name="unselectedIndicatorColor" format="color|reference" />
    <attr name="circleRadius" format="dimension|reference" />
</declare-styleable>

<declare-styleable name="BaseTopBackCenterHeader">
    <attr name="headerTitle" format="reference|string" />
    <attr name="headerTitleColor" format="color|reference" />
    <attr name="headerShowLeft" format="boolean" />
    <attr name="headerLeftTitle" format="reference|string" />
</declare-styleable>
</resources>

Dot(自定义小圆点)文件

public class Dot extends ImageView {
/**
 * 放大放大倍数
 */
public static final float SCALE = 1.0f;
/**
 * 透明度
 */
public static final int ALPHA = 255;

private float[] scaleFloats = new float[]{SCALE, SCALE, SCALE};

private int[] alphas = new int[]{ALPHA, ALPHA, ALPHA,};

public Dot(Context context) {
    this(context, null);
}

public Dot(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs);
}

/**
 * 小圆初始化设置
 *
 * @param context
 * @param attrs
 */
private void init(Context context, AttributeSet attrs) {
    paint = new Paint();
    paint.setAntiAlias(true);// 设置画笔
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值