假装这里有个动图
大概有一个半⚪,表示从日出到日落这段时间,根据当前时间把☀绘制到合适的地方。但是⚪不好看,最后换成椭圆了。
attr.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SunTrack">
<!-- 背景椭圆短轴和长轴长 -->
<attr name="oval_width" format="dimension"/>
<attr name="oval_height" format="dimension"/>
<!-- 表示地平线的直线长 宽 颜色 -->
<attr name="line_length" format="dimension"/>
<attr name="line_width" format="dimension"/>
<attr name="line_color" format="color"/>
<!-- 背景椭圆颜色 太阳轨迹颜色 -->
<attr name="oval_color" format="color"/>
<attr name="track_color" format="color"/>
</declare-styleable>
</resources>
构造函数属性获取
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SunTrack);
if(typedArray!=null){
bgColor = typedArray.getColor(R.styleable.SunTrack_oval_color, Color.BLACK);
trackColor = typedArray.getColor(R