GridView动画水平滑动 [英] GridView animated HORIZONTAL sliding

查看:91
本文介绍了GridView动画水平滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我必须创建一个自定义日历组件,其中包含针对日期的自定义视图-用于不同类型日期的不同视图-正常,事件等-从JSON加载年份配置等.

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. 我通过使用适配器扩展GridView来创建它.
  2. 我已经创建了JSON配置加载等.
  3. 我已经使用网格触摸事件来简化当月的更改.

但是我需要以滑动"左右动画的方式进行操作-就像在Android日历应用程序中一样.

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

例如.我已经在网络上阅读了很多东西,但是仍然找不到有关如何使用GridView进行操作的提示.

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

使用GridView作为基类也许不是最好的主意. 任何帮助将不胜感激.

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

推荐答案

我使用了以下变体:

  • 已加载3页(0、1、2)的ViewPager.
  • 在每个页面上,我都有一个GridView代表日历中的一个月.

第0页是上个月 在第1页是当前月份 在第2页是下个月

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

在ViewPager适配器中,我将适配器用于3个Gridview.

In ViewPager adapter I used adapters for the 3 Gridviews.

最初,我将活动页面设置为1.

Initially I set active page to 1.

每次更改页面时,我都会重新计算上个月,当前月份和下个月的月份数据,然后将活动页面再次设置为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.

这篇关于GridView动画水平滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆