- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个垂直的nestedscrollview,其中包含一堆带有水平布局管理器设置的recyclerview。这个想法与新的 google play 商店的外观非常相似。我能够使其正常工作,但它一点也不流畅。以下是问题:
1) 即使我点击它,水平 recyclerview 项目大多数时候都无法拦截触摸事件。 ScrollView 似乎优先于大多数 Action 。我很难捕获水平运动。这个 UX 令人沮丧,因为我需要尝试几次才能正常工作。如果你查看 play store,它能够很好地拦截触摸事件,而且效果很好。我注意到在 Play Store 中,他们设置的方式是在一个垂直回收 View 中包含许多水平回收 View 。没有 ScrollView 。
2) 水平recyclerviews的高度必须手动设置,并且没有简单的方法来计算子元素的高度。
这是我正在使用的布局:
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:background="@color/dark_bgd"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="gone"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/starring_list"
android:paddingLeft="@dimen/spacing_major"
android:paddingRight="@dimen/spacing_major"
android:layout_width="match_parent"
android:layout_height="180dp" />
这种 UI 模式非常基本,很可能在许多不同的应用中使用。我读过很多 SO,其中 ppl 说将列表放在列表中是一个坏主意,但它是一种非常常见且现代的 UI 模式,到处都在使用。想想 netflix 之类的界面,里面有一系列水平滚动列表一个垂直列表。难道没有一种顺利的方法可以做到这一点吗?
来自商店的示例图片:
最佳答案
因此,平滑滚动问题现已修复。这是由设计支持库(当前为 23.1.1)中的 NestedScrollView 中的错误引起的。
您可以在此处阅读有关该问题和简单修复的信息: https://code.google.com/p/android/issues/detail?id=194398
简而言之,在您执行 throw 之后,nestedscrollview 没有在滚动组件上注册一个完整的,因此它需要一个额外的 'ACTION_DOWN' 事件来释放父 nestedscrollview 拦截(吃掉)后续事件。所以发生的情况是,如果您尝试滚动您的子列表(或 viewpager),在一次 throw 后,第一次触摸会释放父 NSV 绑定(bind),随后的触摸将起作用。这让用户体验非常糟糕。
本质上需要在NSV的ACTION_DOWN事件上添加这一行:
computeScroll();
这是我正在使用的:
public class MyNestedScrollView extends NestedScrollView {
private int slop;
private float mInitialMotionX;
private float mInitialMotionY;
public MyNestedScrollView(Context context) {
super(context);
init(context);
}
private void init(Context context) {
ViewConfiguration config = ViewConfiguration.get(context);
slop = config.getScaledEdgeSlop();
}
public MyNestedScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private float xDistance, yDistance, lastX, lastY;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final float x = ev.getX();
final float y = ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
// This is very important line that fixes
computeScroll();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance) {
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
}
使用该类代替 xml 文件中的nestedscrollview,子列表应正确拦截和处理触摸事件。
唷,实际上有很多这样的错误让我想完全放弃设计支持库,并在它更成熟时重新访问它。
关于android - NestedScrollView 和 Horizontal RecyclerView 平滑滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34258496/
所以我有一个 Fragment,它使用 CoordinatorLayout,里面有一个 NestedScrollView。 NestedScrollView 内部是一个 ViewPager。 View
我知道这个问题很多,但我尝试了几乎所有的解决方案,即使是神奇的解决方案显然对我不起作用!:(父级是 NestedScrollview,在子级中还有另一个嵌套 ScrollView ) pare
我想在滚动式 Instagram 时将 TabLayout 固定在顶部。有没有办法在 NestedScrollView 中执行此操作? NestedScrollView -- ConstraintLa
我的构造中有两个项目,一个是静态项目,另一个是带有可拖动项目的回收 View 。两种类型的 View 都由 LinearLayout 包装。 LinearLayout 由 NestedScrollVi
java.lang.NoSuchMethodError: No virtual method setOnScrollChangeListener(Landroidx/core/widget/Neste
我有一个带有RecyclerView的PagedListAdapter。 当我将RecyclerView放入NestedScrollView中时,PagedList无法计算列表的末尾,因此start请
我将 CollapsingToolbarLayout 与 NestedScrollView 结合使用,在 NestedScrollView 内我有一个项目列表,但在执行中我无法滚动所有项目。 在我的示
我试图将后退按钮保留在页面底部,并让嵌套 ScrollView 填充页面底部统计信息相对布局和后退按钮下方的空间。它目前适合顶部的统计信息,但由于它适合页面,所以将后退按钮推离了页面底部。
所以我在 styles.xml 中为 AppTheme NoActionBar 设置,因为我只希望在几个 Activites 中使用工具栏,并且我还创建了包含两个项目的 post_details_me
这是我 Activity 中的原始布局: 看起来不错: 内容布局文件包含一个 TableLayout。 由于内容可能很长,我添加了一个 Neste
我使用 https://github.com/nhaarman/ListViewAnimations实现拖放,滑动删除等。但是有问题第一个图像可以滚动列表但不能拖放(它下降到相同的位置并且不进入onI
我在 CoordinatorLayout 中有一个 NestedScrollView。在 NestedScrollView 中,我有一个包含一些组件的 LinearLayout,其中一些是按钮。组件没
我注意到 CoordinatorLayout 内的 NestedSCrollView 中的内容如果没有填满整个屏幕,则始终对齐在底部。我该如何解决? 我的代码:
我正在使用 NestedScrollView 以达到某些目的 similar to this . 更新 这是我的 repo . 我发现当移动设备变成横向滚动时,我无法看到按钮或底部的灰色 View 。
我似乎找不到 nestedScrollView 的选项使其水平而不是垂直。我一直在使用 HorizontalScrollView 但我想切换到嵌套。有没有办法做到这一点?搜索文档我没有看到它,但它
我的 xml 由一个约束布局组成。这里面有 2 个按钮和 1 个嵌套的 ScrollView 。 ScrollView 中有各种元素,包括回收 View 。我希望回收 View 不滚动,而只滚动嵌套的
我在 NestedScrollview 中有一个 Recyclerview.. 一切正常,除了一个 thig。我在 NestedScrollview 中共有三个 View ,前两个是 LinearLa
我在我的 fragment 中使用 NestedScrollView。在我的 xml 中的 RelativeLayout 但它没有覆盖整个屏幕高度。 下面是我的代码 - 运行代码时,只有黑色
在我的应用程序中,我需要复杂的 ScrollView 。作为垂直列表和动画标题中的水平列表。下面的代码是一个极简示例,可以使我的问题在 iOS 设备上重现。 我在 flutter 中遇到嵌套 Scro
我正在使用带有标题图像的 CoordinatorLayout 制作详细 View ,我想在具有 NestedScrollView 的 View 中应用圆角边缘,如下所示: 我正在使用带有标题图像的 C
我是一名优秀的程序员,十分优秀!