Android自定义时间线视图 - TimelineView

2016-12-29      344      Android
项目简介

Customizable Timeline View for Android

Android自定义时间线视图,使用很少的代码创建一个简单的时间线列表。你可以调整图像,图像大小,线条颜色和线条大小。

下载

在仓库结尾的根build.gradle中添加:

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

添加依赖:

dependencies {
            compile 'com.github.qapqap:TimelineView:v1.2'
    }

使用方法

在Activity Java类中:

//Create Timeline Rows List
ArrayList<TimelineRow> TimelineRowsList = new ArrayList<>();

// Add Row to the List
TimelineRowsList.add(
        new TimelineRow(
                //Row Id
                1
                //Row Date
                ,new Date()
                //Row Title or null
                ,"Title"
                //Row Description or null
                ,"Description"
                //Row bitmap Image or null
                ,BitmapFactory.decodeResource(getResources(), R.drawable.img_0)
                //Row Bellow Line Color
                , Color.argb(255, 255, 255, 255)
                //Row Bellow Line Size in dp
                , 25
                //Row Image Size in dp
                , 25
                //Row image Background color or -1
                , Color.argb(255, 255, 255, 255)
                //Row image Background Size in dp or -1
                , 25
    )
);

//Create the Timeline Adapter
ArrayAdapter<TimelineRow> myAdapter = new TimelineViewAdapter(this, 0, TimelineRowsList,
//if true, list will be arranged by date
                true);

//Get the ListView and Bind it with the Timeline Adapter
ListView myListView = (ListView) findViewById(R.id.timelineListView);
myListView.setAdapter(myAdapter);

在activity 布局 xml中

<ListView
        android:id="@+id/timelineListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@null"
        android:dividerHeight="0dp"
        >
    </ListView>