Android之NineOldAndroids动画
今天拿到了一套代码看到有
这样一个包,随手查了一下,原来只有元老级Android程序员 比较熟悉这段代码,看了下实现原理,使用的是Jake Wharton的动画开源库NineOldAndroids,这个库究竟是干嘛的呢?在API3.0(Honeycomb 相当老的版本), SDK新增了一个android.animation包,里面的类是实现动画效果相关的类,通过Honeycomb API,能够实现非常复杂的动画效果,但是如果开发者想在3.0以下使用这一套API, 则需要使用开源框架Nine Old Androids,在这个库中会根据我们运行的机器判断其SDK版本,如果是API3.0以上则使用Android自带的动画类,否则就使用Nine Old Androids库中,这是一个兼容库,
实现该效果的主要思路
1,先根据手指触摸的点来获取点击的是ListView的哪一个Item,2
2,当手指在屏幕上面滑动的时候,我们要使得Item跟随手指的滑动而滑动,3,
3,当我们抬起手指的时候,我们根据滑动的距离或者手指在屏幕上面的速度来判断Item是滑出屏幕还是滑动至其实位置,
4,Item滑出屏幕时,使ListView的其他item产生向上挤压或者向下挤压的效果
大致的思路这是这四步,其中的一些细节接下来我会一一为大家解答的,接下来我们就用代码来实现这种效果吧
首先我们新建一个工程,叫Swipedismisslistview,我们需要将Nine Old Androids这个库引入到工程,大家可以去https://github.com/JakeWharton/NineOldAndroids下载,可以使用Jar包,也可以使用工程库的形式引入到我们自己的工程,我们还需要自定义一个ListView,具体怎样使用大家可以网上搜一搜,这不做过多讲解,
下面展示一下Android SDK版本和API Level对照表(最新最全) - CSDN博客
API 25 (Android 7.1)–Nougat, released December 2016. Build version codeAndroid.OS.BuildVersionCodes.NMr1
API 24 (Android 7.0)–Nougat, released August 2016. Build version codeAndroid.OS.BuildVersionCodes.N
API 23 (Android 6.0)–Marshmallow, released August 2015. Build version codeAndroid.OS.BuildVersionCodes.M
API 22 (Android 5.1)–Lollipop, released March 2015. Build version codeAndroid.OS.BuildVersionCodes.LollipopMr1
API 21 (Android 5.0)–Lollipop, released November 2014. Build version codeAndroid.OS.BuildVersionCodes.Lollipop
API 20 (Android 4.4W)–Kitkat Watch, released June 2014. Build version codeAndroid.OS.BuildVersionCodes.KitKatWatch
API 19 (Android 4.4)–Kitkat, released October 2013. Build version codeAndroid.OS.BuildVersionCodes.KitKat
API 18 (Android 4.3)–Jelly Bean, released July 2013. Build version codeAndroid.OS.BuildVersionCodes.JellyBeanMr2
API 17 (Android 4.2-4.2.2)–Jelly Bean, released November 2012. Build version codeAndroid.OS.BuildVersionCodes.JellyBeanMr1
API 16 (Android 4.1-4.1.1)–Jelly Bean, released June 2012. Build version codeAndroid.OS.BuildVersionCodes.JellyBean
API 15 (Android 4.0.3-4.0.4)–Ice Cream Sandwich, released December 2011. Build version codeAndroid.OS.BuildVersionCodes.IceCreamSandwichMr1
API 14 (Android 4.0-4.0.2)–Ice Cream Sandwich, released October 2011. Build version codeAndroid.OS.BuildVersionCodes.IceCreamSandwich
API 13 (Android 3.2)–Honeycomb, released June 2011. Build version codeAndroid.OS.BuildVersionCodes.HoneyCombMr2
API 12 (Android 3.1.x)–Honeycomb, released May 2011. Build version codeAndroid.OS.BuildVersionCodes.HoneyCombMr1
API 11 (Android 3.0.x)–Honeycomb, released February 2011. Build version codeAndroid.OS.BuildVersionCodes.HoneyComb
API 10 (Android 2.3.3-2.3.4)–Gingerbread, released February 2011. Build version codeAndroid.OS.BuildVersionCodes.GingerBreadMr1
API 9 (Android 2.3-2.3.2)–Gingerbread, released November 2010. Build version codeAndroid.OS.BuildVersionCodes.GingerBread
API 8 (Android 2.2.x)–Froyo, released June 2010. Build version codeAndroid.OS.BuildVersionCodes.Froyo
API 7 (Android 2.1.x)–Eclair, released January 2010. Build version codeAndroid.OS.BuildVersionCodes.EclairMr1
API 6 (Android 2.0.1)–Eclair, released December 2009. Build version codeAndroid.OS.BuildVersionCodes.Eclair01
API 5 (Android 2.0)–Eclair, released November 2009. Build version codeAndroid.OS.BuildVersionCodes.Eclair
API 4 (Android 1.6)–Donut, released September 2009. Build version codeAndroid.OS.BuildVersionCodes.Donut
API 3 (Android 1.5)–Cupcake, released May 2009. Build version codeAndroid.OS.BuildVersionCodes.Cupcake
API 2 (Android 1.1)–Base, released February 2009. Build version codeAndroid.OS.BuildVersionCodes.Base11
API 1 (Android 1.0)–Base, released October 2008. Build version codeAndroid.OS.BuildVersionCodes.Base