Android自定义控件——Indicator

Indicator确实是个老梗了...

有重写HorizontalScrollView的,有重写LinearLayout。

这个是重写LinearLayout的哦,往LinearLayout里add   TextView用作tab标签,在LinearLayout底部画一个矩形当作指示器。

ViewPager滚动的时候用简单的小学加减乘除混合运算来机选这个矩形位置,然后滚动就好了



属性

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <attr name="tab_color_normal" format="color" />
    <attr name="tab_color_light" format="color" />
    <attr name="cursor_color" format="color" />
    <attr name="cursor_height" format="dimension" />

    <declare-styleable name="Indicator">
        <attr name="tab_color_normal" />
        <attr name="tab_color_light" />
        <attr name="cursor_color" />
        <attr name="cursor_height" />
    </declare-styleable>

</resources>

Indicator.java  关键的地方都谢了注释

package com.mingwei.indicator.view;

import java.util.List;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
im
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值