Android 自定义控件之时间轴布局(TimeLineLayout)

1,643 阅读1分钟
原文链接: github.com

This is a timeline layout. (这是一个时间轴布局)

预览

使用

  • 布局中:
 <com.github.airsaid.timelinelayout.widget.TimeLineLayout
        android:id="@+id/timeLineLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:paddingLeft="20dp"
        android:paddingRight="16dp"
        app:tll_dotColor="@color/colorAccent"
        app:tll_dotRadius="4dp"
        app:tll_height="40dp"
        app:tll_lineColor="#E4E4E4"
        app:tll_lineWidth="1px"
        app:tll_padding="16dp"
        app:tll_textColor="@android:color/black"
        app:tll_textSize="14sp"/>
  • 代码中:
ArrayList<CharSequence> data = new ArrayList<>();
data.add("拍摄时间:2017-9-10至2017-11-20");
data.add("拍摄周期:1");
data.add("拍摄地址:北京");
data.add("出品方:某某传媒");
data.add("报名截止日期:2017-09-30");

TimeLineLayout timeLineLayout = (TimeLineLayout) findViewById(R.id.timeLineLayout);
timeLineLayout.setData(data);

自定义属性

<!--时间轴样式布局-->
    <declare-styleable name="TimeLineLayout">
        <!--每行高度-->
        <attr name="tll_height" format="dimension|reference"/>
        <!--文字大小-->
        <attr name="tll_textSize" format="dimension|reference"/>
        <!--文字颜色-->
        <attr name="tll_textColor" format="color|reference"/>
        <!--文字和时间轴间距-->
        <attr name="tll_padding" format="dimension|reference"/>
        <!--时间轴圆点颜色-->
        <attr name="tll_dotColor" format="color|reference"/>
        <!--时间轴圆点半径-->
        <attr name="tll_dotRadius" format="dimension|reference"/>
        <!--时间线颜色-->
        <attr name="tll_lineColor" format="color|reference"/>
        <!--时间线宽度-->
        <attr name="tll_lineWidth" format="dimension|reference"/>
    </declare-styleable>

联系我