android 横向滑动日期_Android时间线在recyclerview中显示水平滑动卡,按日,月或年分组...

Android-Timeline-View

Android timeline to display horizontal sliding cards in recycler view, group by Day, Month or Year.

Apps using the library:

PS: Please let me know if you are using this library in your app to list here. email: ark.akshaykale@gmail.com)

Install

Add following to application level build.gradle file

dependencies {

//...

compile 'com.akshaykale.android:android-timeline-view:2.1'

}

Usage

Timeline view can be loaded directly as a Fragment.

Add a container to load the fragment.

activity_main.xml

android:layout_marginTop="65dp"

android:id="@+id/container"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

MainActivity.java

// instantiate the TimelineFragment

TimelineFragment mFragment = new TimelineFragment();

//Set data

mFragment.setData(loadData(), TimelineGroupType.MONTH);

//Set configurations

mFragment.addOnClickListener(this);

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

transaction.replace(R.id.container, mFragment);

transaction.commit();

Load the data into Timeline using loadDataInTimeline() function

private ArrayList loadDataInTimeline() {

//Load the data in a list and sort it by times in milli

ArrayList objs = new ArrayList<>();

objs.add(new TestO(Long.parseLong("1483196400000"), "A", "url"));

objs.add(new TestO(Long.parseLong("1483196400000"), "A", "url"));

objs.add(new TestO(Long.parseLong("1483196400000"), "B", "url" ));

objs.add(new TestO(Long.parseLong("1483196400000"), "C" , "url"));

objs.add(new TestO(Long.parseLong("1484146800000"), "D" ,c"url"));

//Sort and return

//Sort logic

return objs;

}

Load single object into timeline using addSingleObject() function

TestO object = new TestO(Long.parseLong("1481196400000"), "ZZZ", "http://www.pics4learning.com/images/categories/cat-biome-360.jpg");

mFragment.addSingleObject(object, TimelineGroupType.DAY);

TestO.java

Every data object must implement TimelineObject and override the methods and return valid value.

public class TestO implements TimelineObject {

long timestamp;

String name, url;

@Override

public long getTimestamp() {

return timestamp;

}

@Override

public String getTitle() {

return name;

}

@Override

public String getImageUrl() {

return url;

}

}

Use different image loading library

For Image loading this library uses Picasso, But you can use any library you preffer to load the image. For this, create a class ImageLoad which implements ImageLoadingEngine

public class ImageLoad implements ImageLoadingEngine {

@Override

public void onLoadImage(ImageView imageView, String uri) {

// Use any library you prefer to load the image into the view

// For Ex: Glide, Picasso, UIL, etc.

}

}

And before loading the fragment into the container add following line of code.

mFragment.setImageLoadEngine(new ImageLoad(getApplicationContext()));

Configurations

Function

Usage

addOnClickListener();

Implement click events on the timeline objects

1. void onTimelineObjectClicked(TimelineObject object){...}

2. void onTimelineObjectLongClicked(TimelineObject object) {...}

setData(ArrayList list, TimelineGroupType type)

Set data to the timeline.

Parameters:

1. List of TimelineObjects.

Ex:

class Food implements TimelineObject{...}

2. Group type:

a> TimelineGroupType.DAY

b>TimelineGroupType.MONTH

c>TimelineGroupType.YEAR

addSingleObject(TimelineObject object, TimelineGroupType type)

Add a single object to the timeline.

Parameters:

1. TimelineObject.

Ex:

class Food implements TimelineObject{...}

2. Group type:

a> TimelineGroupType.DAY

b>TimelineGroupType.MONTH

c>TimelineGroupType.YEAR

setImageLoadEngine(ImageLoadingEngine engin)

Add custom image loading logic

setTimelineHeaderSize(int size)

Text size of the date header

setTimelineHeaderTextColour(String textColour)

Set text colour of date header

setTimelineIndicatorBackgroundColour(String textColour)

Change the background colour of Timeline indicator

setTimelineIndicatorLineColour(String textColour)

Chenge the timeline indicator line colour

setTimelineCardTextSize(int size)

Change the text size of timeline card

setTimelineCardTextBackgroundColour(String textColour)

Change the text background colour of card

MIT License

Copyright (c) 2017 Akshay Kale

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值