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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个相对复杂的问题,需要一定的Android开发经验和知识。我会简单地讲解一下实现的大致思路和步骤。 1. 自定义LayoutManager 首先需要自定义一个LayoutManager,它会负责RecyclerView每个item的布局排列和滚动。在这个LayoutManager,我们需要重载一些方法,例如`onLayoutChildren()`,`scrollHorizontallyBy()`,`generateDefaultLayoutParams()`等。这些方法的具体实现会根据我们的需求而不同。其,`onLayoutChildren()`方法负责测量和布局RecyclerView的每一个ItemView,`scrollHorizontallyBy()`方法负责水平滚动RecyclerView,`generateDefaultLayoutParams()`方法负责生成默认的LayoutParams。 2. 实现弧形效果 要实现弧形效果,我们需要使用贝塞尔曲线。具体来说,我们可以通过计算贝塞尔曲线上的点来实现在RecyclerView弧形排列ItemView。这个过程可以在`onLayoutChildren()`方法实现。我们可以通过计算每个ItemView的位置和角度来获得它的坐标,然后将这些坐标传递给View进行布局。 3. 实现滑动放大效果 要实现滑动放大效果,我们可以在`scrollHorizontallyBy()`方法监听RecyclerView滑动距离,然后根据距离计算每个ItemView的缩放比例。具体来说,我们可以在滑动过程计算每个ItemView心点和RecyclerView心点之间的距离,然后根据距离计算缩放比例。我们可以使用`setScaleX()`和`setScaleY()`方法来设置ItemView的缩放比例。 以上是实现弧形以及滑动放大效果RecyclerView的大致思路和步骤。具体的实现过程还需要考虑很多细节问题,例如ItemView的位置和角度计算、动画效果的处理等等。如果您需要更详细的信息,请参考相关的开发文档或者查找相关的示例代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值