无缝嵌套滚动(安卓) [英] Seamless nested scrolling (Android)

查看:216
本文介绍了无缝嵌套滚动(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都被告知对包含滚动机制嵌套的看法。不过,在最新的Andr​​oid版本(5.0),手机应用程序吸引了我的注意什么似乎是一个的ListView 内部的滚动型

We've all been advised against nesting views that contain a scrolling mechanism. However, in the latest Android release (5.0), the Phone app caught my attention with what seems to be a ListView inside of a ScrollView.

真正吸引了我是,滚动机制从滚动型切换到的ListView 无缝连接。 演示 https://dl.dropboxusercontent.com/u/ 244748 / recording.mp4

What really intrigued me was that the scrolling mechanism switched from the ScrollView to the ListView seamlessly. Demo: https://dl.dropboxusercontent.com/u/244748/recording.mp4.

注意标签上面的内容被推出来查看实际的ListView 开始滚动。

Notice the content above the tabs is pushed out of view before the actual ListView begins scrolling.

我试图复制这个自己,但最终未果。这是基本的做法我正在...

I've tried duplicating this myself, but ended up unsuccessful. Here is the basic approach I was taking...

通过一个单一的,连续的触摸事件(没有解除手指)...

With a single, continuous touch event (no lifting of the finger) ...

随着用户滚动时,的ListView 慢慢地掩盖了的ImageView 。一旦的ImageView 100%覆盖和的ListView 占据了整个屏幕,在的ListView 开始滚动。

As user scrolls, the ListView slowly covers up the ImageView. Once the ImageView is 100% covered and the ListView takes up the entire screen, the ListView begins to scroll.

目前,我正在听触及 ListView控件的事件,如果顶部已经到达,呼叫 requestDisallowInterceptTouchEvent 的ListView ,即

I'm currently listening to touch events on the ListView and if the top has been reached, call requestDisallowInterceptTouchEvent on the ListView, i.e.

@Override
public boolean onTouch(View v, MotionEvent event) {
  if (listViewAtTop) {
    v.requestDisallowInterceptTouchEvent(true);
  } else {
    v.requestDisallowInterceptTouchEvent(false);
  }
  return false;
}

切换滚动的情况下工作,只有当你抬起手指,继续滚动。

The switching scrolling context works, only if you lift your finger and continue scrolling.

是否有不同的方法,将达到预期的效果?

Is there a different approach that will achieve the desired effect?

推荐答案

安卓5.0棒棒堂(API 21)加入嵌套的滚动支持。

Android 5.0 Lollipop (API 21) added nested scrolling support.

这是我可以告诉,双方的ListView(AbsListView)和滚动型现在支持这个(如果在API 21上运行),但必须在滚动视图中启用。

From what I can tell, both ListView (AbsListView) and ScrollView support this now (if running on API 21), but it must be enabled on the scrolling views.

有两种方式,通过调用 <一href="http://developer.android.com/reference/android/view/View.html#setNestedScrollingEnabled(boolean)">setNestedScrollingEnabled(true)或布局属性机器人:nestedScrollingEnabled =真(这是无证)

There are two ways, by calling setNestedScrollingEnabled(true) or with the layout attribute android:nestedScrollingEnabled="true" (which is undocumented)

要了解它是如何工作,或者支持此为自定义窗口小部件,关键的方法是这些:

To learn about how it works, or to support this for a custom widget, the key methods are these:

  • <一个href="http://developer.android.com/reference/android/view/ViewParent.html#onStartNestedScroll(android.view.View,%20android.view.View,%20int)">onStartNestedScroll

<一个href="http://developer.android.com/reference/android/view/ViewParent.html#onNestedScrollAccepted(android.view.View,%20android.view.View,%20int)">onNestedScrollAccepted

<一个href="http://developer.android.com/reference/android/view/ViewGroup.html#onNested$p$pScroll(android.view.View,%20int,%20int,%20int[])">onNested$p$pScroll

<一个href="http://developer.android.com/reference/android/view/ViewParent.html#onNestedScroll(android.view.View,%20int,%20int,%20int,%20int)">onNestedScroll

<一个href="http://developer.android.com/reference/android/view/ViewGroup.html#onStopNestedScroll(android.view.View)">onStopNestedScroll

不幸的是,没有任何指导或培训这也解释了它是如何工作比JavaDoc的本身,这是相当轻其他,有没有例子不是滚动型等。

Unfortunately, there is no guide or training which explains how this works other than the JavaDoc itself which is rather light and there are no examples other than ScrollView.

这篇关于无缝嵌套滚动(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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