- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 Lollipop 的电话应用程序中,当您到达“最近”或“联系人”选项卡并尝试滚动时,首先发生的是调整上部区域的大小,该区域由最近的事件和搜索框组成,如这样的:
如果 RecyclerView 上有超过 3 个项目,只要上部区域可以缩小到最小尺寸,RecyclerView 就不会向下滚动。
向上滚动也是如此:只要上部区域没有完全放大,RecyclerView 就不会向上滚动。
我找不到实现此功能的最佳方法。
更具体地说,我对调整上部区域的大小有疑问,这样它就会像在 Lollipop 上一样流畅。
为简化起见,我只需要调整屏幕的一部分,而不是手机应用程序(“最近的事件”和搜索框)上显示的两部分。
我尝试过很多事情:
使 RecyclerView 变得和整个屏幕一样大,同时有一个假的、大的、空的标题。当我滚动时,我还将“translationY”设置为顶部的真实内容。这存在将滚动条显示为上部区域的一部分的问题(我想在正确的位置显示滚动条)。此外,它还变得非常复杂,因为您还必须处理其他页面的 RecyclerViews 滚动值。这是类似于一些第三方库的解决方案,例如 this one (但在这里我使用的是布局而不是 ImageView,但代码几乎相同)。
RecyclerView在上方区域下方,滚动改变上方区域的layoutParams,和我在this post上做的类似.
与 2 相同,但我没有更改 LayoutParams,而是更改了 View 的 scaleY。
对于#2 和#3,问题是在某些情况下,一旦我得到某个值的 +Y 滚动事件,我也会得到相同值的 -Y 的滚动事件(并且反之亦然),使调整大小效果的处理“跳跃”(向上和向下,即使用户很好地滚动)。
我猜测为什么会发生这种情况是因为当我移动 RecyclerView 时,用户进行的下一个事件位于与原始事件完全不同的位置,因为我已经更改了 RecyclerView 的定位方式或其大小.
我尝试同时使用 setOnTouchListener (甚至连同 GestureDetectorCompat )和 setOnScrollListener .所有这些都导致了同样奇怪的问题。
我该如何解决这个问题?为什么会发生,为什么不总是发生?
编辑:我试图更改 #2,这样我就不会处理 RecyclerView 的触摸事件,而是处理其容器(一些 LinearLayout)的触摸事件。出于某种原因,容器没有响应触摸事件,所以我将其替换为 RelativeLayout,并在此布局内的所有内容之上放置一个 View ,它将响应触摸事件(并相应地更改上部区域)。这行得通,但随后我无法在需要时将事件进一步传递给 subview 。
我认为最好的办法是自定义 RecyclerView(扩展它)触摸处理。也许添加一个滚动监听器,当 RecyclerView 即将滚动时,它会询问是否可以,如果没有,它不会尝试滚动,直到触发触摸事件并重置其状态。
最佳答案
好吧,一个解决方案(我仍然不喜欢,但有效)是使用“TouchInterceptionFrameLayout”类(来自 the library 我发现),这将允许你要决定何时允许滚动、何时不允许滚动以及何时不应该滚动,您可以更改同时具有分页选项卡和 ViewPager 的布局的填充(或您希望的内容)。
viewPager&tabs 的容器覆盖了整个区域,并且有一个变化的填充。
这是布局:
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<!-- put upper content here -->
</LinearLayout>
<LinearLayout
android:id="@+id/pagerAndTabsContainer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/viewPagerSlidingTabsStrip"
android:layout_width="match_parent"
android:background="@color/default_background"
android:layout_height="48dip"/>
<android.support.v4.view.ViewPager
android:background="@color/default_background"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout>
然后,您需要一些初始化代码(布局阶段完成后,您可以获得 View 的实际大小):
// the upper area height, that can be shrunk to a size of 0 height when needed
mResizeableViewHeight = mHeaderView.getHeight();
// set initial padding if you wish to show the upper area by default
mPagerAndTabsContainer.setPadding(0, mResizeableViewHeight, 0, 0);
prepareViewPager(mViewPager); // set the pages and fragments...
// init the "TouchInterceptionFrameLayout" to handle touch events
mContentView.setScrollInterceptionListener(mInterceptionListener);
在 TouchInterceptionFrameLayout.TouchInterceptionListener 的“shouldInterceptTouchEvent”函数上,你决定什么时候应该阻止触摸,在这个接口(interface)的“onMoveMotionEvent”上你应该处理被阻止的触摸。
对于每个具有 recyclerView 的 fragment ,使用 ObservableRecyclerView 代替,并调用这些行:
// get the fragment that shows the screen I've made (with the layout)
Fragment fragment = getTargetFragment();
// let the recyclerView handle filtered touches
mRecyclerView.setTouchInterceptionViewGroup(((IGetContainer) fragment).getContainer());
// if you wish to put animations when you do a touch-up event, this may be handy (or use onUpOrCancelMotionEvent of the "TouchInterceptionListener" too/instead ) :
if (fragment instanceof ObservableScrollViewCallbacks)
mRecyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) fragment);
我不太喜欢这个解决方案,因为它用触摸包装覆盖了整个屏幕,因为它会导致 viewPager 的 overdraw (并且需要你为它设置背景),并且因为它与我的想法。它也比 Lollipop 的 Phone 应用程序流畅得多,无论我如何使用滚动规则。
我可以让 TouchInterceptionListener 仅在触摸事件源自 RecyclerView 时才开始处理触摸事件,但这会使它的复杂性变得更糟。
关于android - 如何模仿 Lollipop 的手机应用程序,在可滚动内容之前调整上部项目的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27997948/
我正在寻找一种使此打印 HTML 代码 fragment 向后兼容旧 Android 版本的简单方法: @TargetApi(Build.VERSION_CODES.KITKAT) private v
我在 GCC 终端 (centos linux) 中为 ATM 项目编译以下 c 和 .h 代码时收到以下错误。请帮忙,因为我是编程新手。 validate_acc.h #ifndef _VALIDA
在写关于 SO 的不同问题的答案时,我制作了这个片段: @import url('https://fonts.googleapis.com/css?family=Shadows+Into+Light'
试图弄清楚我应该如何在 my_div_class 之前放置一个 span 而不是替换所有它。现在它取代了 div,但我不想这样做。我假设它类似于 :before 但不知道如何使用它。 { va
我正在使用选择库 http://github.hubspot.com/select/和 noUiSlider https://refreshless.com/nouislider/ .我面临的问题如下
我是开发新手,独自工作。我正在使用 Xcode 和 git 版本控制。可能我没有适本地组织和做错事,但我通常决定做 promise 只是为了在我破坏一切之前做出安全点。在那一刻,我发现很难恰本地描述我
我想确保在同一个桶和键上读取和写入时,应该更新获取的值,也就是说,应该在对其进行写入操作之后获取它。我怎样才能做到这一点? 我想要的是,如果我更新一个键的值,如果我同时使用不同线程获取值,则更新同一个
我的问题与this有关问题,已经有了答案: yes, there is a happens-before relationship imposed between actionsof the thre
The before and after hook documentation on Relish仅显示 before(:suite) 在 before(:all) 之前调用。 我什么时候应该使用其中
我有 CSV 行,我想在其中检测所有内部双引号,没有文本限定符。这几乎可以正常工作,但我的正则表达式还可以检测双引号后的字符。 CSV 部分: "7580";"Lorem ipsum";"";"Lor
是否可以通过Youtube数据API检查广告是否可以与特定视频一起显示? 我了解contentDetails.licensedContent仅显示视频是否已上传至同一伙伴然后由其声明版权。由于第三者权
考虑一下用漂亮的彩色图表描述的“像素管道” https://developers.google.com/web/fundamentals/performance/rendering/ 我有一个元素(比
之前?
在 MVC3 中,我可以轻松地将 jQuery 脚本标签移动到页面底部“_Layout.vbhtml” 但是,在 ASP.NET MVC3 中,当您使用编辑器模板创建 Controller 时,脚手
悬停时内容被替换,但是当鼠标离开元素时我希望它变回来。我该怎么做? $('.img-wrap').hover(function(){ $(this).find('h4').text('Go
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码以重现该问题。
版本:qwt 6.0.1我尝试开发频谱的对数缩放。我使用简单的线条来启用缩放plotspectrum->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10S
我有两个相同的表,I_Subject 和 I_Temp_Subject,我想将 Temp_Subject 表复制到 Subject 表。 I_Temp_Subject 由简单用户使用,I_Subjec
我的印象是第一次绘制发生在触发 DOMContentLoaded 事件之后。特别是,因为我认为为了让第一次绘制发生,需要渲染树,它依赖于 DOM 构造。另外,我知道 DOM 构造完成时会触发 DOMC
我是一名优秀的程序员,十分优秀!