道客优

1234
安卓时间线布局及多样进度源码
2019-09-17 刀刻油 阅读:1283

showcase.png

Line Padding around marker
<com.github.vipulasri.timelineview.TimelineView
    android:id="@+id/timeline"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:markerSize="20dp"
    app:lineWidth="2dp"
    app:startLineColor="@color/colorPrimary"
    app:endLineColor="@color/colorPrimary"
    app:linePadding="5dp"/>
  • Configure using xml attributes or setters in code:

    Attribute NameDefault ValueDescription
    app:marker="@drawable/marker"Green Colored Oval Drawablesets marker drawable
    app:markerSize="25dp"25dpsets marker size
    app:markerInCenter="false"truesets the marker in center of line if `true`
    app:startLineColor="@color/primarColor"Dark Grey Linesets start line color
    app:endLineColor="@color/primarColor"Dark Grey Linesets end line color
    app:lineWidth="2dp"2dpsets line width
    app:lineOrientation="horizontal"verticalsets orientation of line ie `horizontal` or `vertical`
    app:linePadding="5dp"0dpsets line padding around marker
    app:lineStyle="dash"normalsets line style ie `normal` or `dashed`
    app:lineStyleDashGap="4dp"4dpsets line dash gap
    app:lineStyleDashLength="8dp"8dpsets line dash length
  • RecyclerView Holder : Your RecyclerViewHolder should have an extra parameter in constructor i.e viewType from onCreateViewHolder. You would also have to call the method initLine(viewType) in constructor definition.

    public class TimeLineViewHolder extends RecyclerView.ViewHolder {        public  TimelineView mTimelineView;        public TimeLineViewHolder(View itemView, int viewType) {            super(itemView);
            mTimelineView = (TimelineView) itemView.findViewById(R.id.timeline);
            mTimelineView.initLine(viewType);
        }
    }
  • RecyclerView Adapter : override getItemViewType method in Adapter

    @Override
    public int getItemViewType(int position) {        return TimelineView.getTimeLineViewType(position, getItemCount());
    }

And pass the viewType from onCreateViewHolder to its Holder.

    @Override
    public TimeLineViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {        View view = View.inflate(parent.getContext(), R.layout.item_timeline, null);        return new TimeLineViewHolder(view, viewType);
    }

源码下载

推荐阅读: