GridView animated HORIZONTAL sliding

落花浮王杯 提交于 2020-03-25 17:54:08

问题


For one reason or another, I had to create a custom calendar component with custom views for days - different views for different types of dates - normal, events, etc - loading year configuration from JSON, etc.

  1. I've created it by extending the GridView with an adapter.
  2. I've created JSON-configuration loading etc.
  3. I've used grid touch events to make changing of current month easy.

But I need to do this "sliding" left and right animated - as it is in the android calendar application.

for example. I've read a lot on the web, but I still cannot find any tips on how to do this with GridView.

Maybe it was not the best idea to use GridView as a base class. Any help would be appreciated.


回答1:


I've used the following variant:

  • ViewPager which has 3 pages (0, 1, 2) loaded.
  • On each page I have a GridView representing a month from the calendar.

On page 0 is the previous month On page 1 is the current month On page 2 is the next month

In ViewPager adapter I used adapters for the 3 Gridviews.

Initially I set active page to 1.

On each page change I recalculate the month data for previous, current and next month and set active page again to 1.

This way I simulate something like "infinite" view pager. For the moment it's ok for my task - sliding pages calendar.



来源:https://stackoverflow.com/questions/60236823/gridview-animated-horizontal-sliding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!