问题
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.
- I've created it by extending the GridView with an adapter.
- I've created JSON-configuration loading etc.
- 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