Android开发之-类似iPhone弹性效果的BounceListView
2012-04-16 16:03
330 查看
I continued to look into Android's new Overscroll functionality introduced in Gingerbread and discovered some more interesting things. The functionality to make a a view scroll beyond its limits and then bounce back (almost exactly like iOS) is sort of built
into the framework, but just hidden. I'm not sure exactly why it has been built like it has been, but I will give a few guesses after an explanation of what is actually going on, but first: DEMO!
find two variables of interest: OVERSCROLL_DISTANCE and OVERFLING_DISTANCE. These two variables tell the framework how much a view should be able to scroll beyond its limits. They are hard coded in and there are no methods available to set your own custom
ones. OVERSCROLL_DISTANCE is set to 0 (!?) and OVERFLING_DISTANCE is set to 4.
For those that don't know, the ViewConfiguration class holds a set of values that Android uses to store the default timeouts / distances
etc for certain UI behaviours. It also does some internal scaling and calculations based on screen density etc. If you're interested, have a look at the source
So with OVERSCROLL_DISTANCE set to 0, the view will never move beyond its limits, but you can do something fairly simple to achieve this behaviour.
In complicated terms, just extend the view you wish to use normally, (e.g. ListView) and override the overScrollBy method.
Then within theoverScrollBy method body, simply call the super.overScrollBy
but with your own values for maxOverScrollX and/or maxOverScrollY. If you're gonna do this, make sure you scale your values based on the screen density.
Confused? Have a code sample:
And now just use that custom view wherever you would normally have used the standard view!
?
?
As promised, some guesses as to why this is happening. My first thought is that the developers had no intention of exposing this functionality and that it is simply meant to be used
for the small springback you get after an overfling (remember where OVERFLING_DISTANCE was set to 4). But then is that was the case why set OVERSCROLL_DISTANCE to 0, why not just not include it if that was the case? Maybe they are planning something in the
future? But if it was intended to be used, then why not create methods that let you set the overscroll distances for your views? Who knows…
from:http://www.cnblogs.com/thinkfeed/archive/2011/09/19/2181042.html
into the framework, but just hidden. I'm not sure exactly why it has been built like it has been, but I will give a few guesses after an explanation of what is actually going on, but first: DEMO!
So What's There and What Isn't?
I'm glad you asked… If we look into the ViewConfiguration class' source wefind two variables of interest: OVERSCROLL_DISTANCE and OVERFLING_DISTANCE. These two variables tell the framework how much a view should be able to scroll beyond its limits. They are hard coded in and there are no methods available to set your own custom
ones. OVERSCROLL_DISTANCE is set to 0 (!?) and OVERFLING_DISTANCE is set to 4.
For those that don't know, the ViewConfiguration class holds a set of values that Android uses to store the default timeouts / distances
etc for certain UI behaviours. It also does some internal scaling and calculations based on screen density etc. If you're interested, have a look at the source
So with OVERSCROLL_DISTANCE set to 0, the view will never move beyond its limits, but you can do something fairly simple to achieve this behaviour.
In complicated terms, just extend the view you wish to use normally, (e.g. ListView) and override the overScrollBy method.
Then within theoverScrollBy method body, simply call the super.overScrollBy
but with your own values for maxOverScrollX and/or maxOverScrollY. If you're gonna do this, make sure you scale your values based on the screen density.
Confused? Have a code sample:
And now just use that custom view wherever you would normally have used the standard view!
?
?
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <com.thinkfeed.bouncelistview.BounceListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.thinkfeed.bouncelistview" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".BounceListViewActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
As promised, some guesses as to why this is happening. My first thought is that the developers had no intention of exposing this functionality and that it is simply meant to be used
for the small springback you get after an overfling (remember where OVERFLING_DISTANCE was set to 4). But then is that was the case why set OVERSCROLL_DISTANCE to 0, why not just not include it if that was the case? Maybe they are planning something in the
future? But if it was intended to be used, then why not create methods that let you set the overscroll distances for your views? Who knows…
from:http://www.cnblogs.com/thinkfeed/archive/2011/09/19/2181042.html
相关文章推荐
- Android开发之-类似iPhone弹性效果的BounceListView
- Android开发之-类似iPhone弹性效果的BounceListView
- ANDROID开发之-类似IPHONE弹性效果的BOUNCELISTVIEW
- Android开发之ListView添加多种布局效果演示
- android开发之ExpandableListView的使用,实现类似QQ好友列表
- iOS开发之实现图片自动切换(类似android画廊效果)
- Android ListView弹性效果的实现方法
- Android基于ListView实现类似QQ空间的滚动翻页与滚动加载效果
- android开发之ExpandableListView的使用,实现类似QQ好友列表
- Android开发:GridView与ListView相互切换(动画效果)
- Android 实现ListView的弹性效果
- 类似iPhone的弹性ListView滚动
- Android 实现ListView的弹性效果
- android应用开发,类似美团商品详情下拉,顶部图片放大的效果
- Android 弹性ListView和ScrollView 简单优雅地实现回弹效果
- [转]Android开发:Parallax效果的ScrollerView,改编自ParallaxListView
- android开发教程之实现listview下拉刷新和上拉刷新效果
- iOS开发之类似Android中Toast效果制作
- Android ListView嵌套GridView(同理嵌套ListView)类似QQ说说条目加点赞显示名称效果
- Android开发之具有弹性的ListView